Home > Software engineering >  Just started to learn vb.net, feel there should be a simple writing, the predecessor instruct me.
Just started to learn vb.net, feel there should be a simple writing, the predecessor instruct me.

Time:09-23

 
Private Sub But_add_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles But_add. Click




Dim chaxunmubiao As String=ComboBox1. Text

Dim Var_number As String=Tex_number. Text
'* number
Dim Var_name As String=Tex_name. Text
'* name
Dim Var_dbrname As String=Tex_dbrname. Text
'* guarantor name
Dim Var_sex As String=Tex_sex. Text
'* gender
Dim Var_csrq As String=Tex_csrq. Text
'date of birth
Dim Var_age As String=Tex_age. Text
Age
'Dim Var_rzsj As String=Tex_rzsj. Text
'
* check in timeDim Var_fjh As String=Tex_fjh. Text
'* room number
Dim Var_huji As String=Tex_huji. Text
'the census register seat
Dim Var_id As String=Tex_id. Text
'* id
Dim Var_zp As String=PictureBox1. ImageLocation
'the picture
Dim Var_rzyy As String=Tex_rzyy. Text
'check-in reason
Dim Var_tjzl As String=Tex_tjzl. Text
'medical information
Dim Var_fwjb As String=Tex_fwjb. Text
'service level
Dim Var_yzyj As String=Tex_yzyj. Text
'dean comments

Try
If Var_number & lt;> "Null" & amp; Var_name & lt;> "Null" Then
Dim cnStr As String="Data Source=(local); Initial Catalog=yly; Integrated Security=true;"
Cn=New SqlConnection (cnStr)
Dim da_Str As String="insert into"
Da_Str +=chaxunmubiao
Da_Str +="values"
Da_Str +="("
Dim a As String="'"
Dim b As String=", "
Da_Str +=a + Var_number + a + b
'* number
Da_Str +=a + Var_name + a + b
'* name
Da_Str +=a + Var_dbrname + a + b
'* guarantor name
Da_Str +=a + Var_sex + a + b
'* gender
Da_Str +=a + Var_csrq + a + b
'date of birth
Da_Str +=a + Var_age + a + b
Age
'Da_Str +=a + Var_rzsj + a + b
'
* check in timeDa_Str +=a + Var_fjh + a + b
'* room number
Da_Str +=a + Var_huji + a + b
'the census register seat
Da_Str +=a + Var_id + a + b
'* id
'da_Str + a + a + b=
Da_Str +=a + Var_zp + a + b
'the picture
Da_Str +=a + Var_rzyy + a + b
'check-in reason
Da_Str +=a + Var_tjzl + a + b
'medical information
Da_Str +=a + Var_fwjb + a + b
'service level
Da_Str +=a + Var_yzyj + a
Da_Str +=") "
'"' Label1. Text=da_Str
Da=New SqlDataAdapter (da_Str, cn)
'the insert into the old information
'values (' 20161212', '999', 'zhang five' and 'male', ' 'and', '20160821', '107', ', '231025198505015717', ' 'and', ', ', ')
Ds=New DataSet ()
Da. The Fill (ds, "grade1")
DataGridView1. The DataSource=ds. The Tables (" grade1)
End the If
Catch the ex As Exception
MsgBox (" red is must fill in the item, and can't be empty! Please fill in again!" )
End the Try


End Sub


Please write simple spelled out! thank you

CodePudding user response:

Search "code generation"

CodePudding user response:

 
The String. Format (" insert into {0} values (' ", chaxunmubiao) & amp;
The Join ({variables 1, 2... }, "', '") & amp;
"')
"

SQL is an insert statement, and you really didn't try to fill the results to the ds inside is what appearance,
  • Related