insert 语句运放到查询分析器里能正常运行 在 VB.NET下不能运行 望赐教,感激不尽!!
worker 表结构如附件
代码如下:
Me.birthday.Format = DateTimePickerFormat.Short
Me.Label36.Text = ""
If Me.txtdepartment.Text.Trim = "" Then
Me.Label36.Text = ""
Me.Label36.Text = "部门不能为空"
Exit Sub
ElseIf txtID.Text.Trim = "" Then
Me.Label36.Text = ""
Me.Label36.Text = "职工编号不能为空"
Exit Sub
ElseIf TxtName.Text.Trim = "" Then
Me.Label36.Text = ""
Me.Label36.Text = "职工姓名不能为空"
Exit Sub
Else
Dim marr As String
If Me.cbomarriage.Text = "未婚" Then
marr = 1
ElseIf Me.cbomarriage.Text = "已婚" Then
marr = 2
ElseIf Me.cbomarriage.Text = "离异" Then
marr = 3
Else
marr = 4
End If
Me.Label36.Text = ""
com.CommandText = "insert worker (id,name,sex, " & _
"birthdate,education,school,nation,polity,specialty, " & _
"place,marriage,address,postalcode,email,phone,idcard, " & _
"post,duty,dutystatus,department,foreignlevel,languagetype, " & _
"computerlevel,bankcard,bank,safetycard,startworkdate, " & _
"lengthservice,paylevel,intime,outtime,ownlengthservice, " & _
"startpactdate,endpactdate) " & _
"values(" & txtID.Text.Trim & ",'" & TxtName.Text.Trim & "', " & _
"'" & Me.CboSex.Text.Trim & "'," & Me.birthday.Text.Trim & ", " & _
"'" & Me.txtEducation.Text.Trim & "','" & Me.txtschool.Text.Trim & "', " & _
"'" & Me.TxtNation.Text.Trim & "','" & Me.Cbopolity.Text.Trim & "', " & _
"'" & Me.txtSpecial.Text.Trim & "','" & Me.txtPlace.Text.Trim & "', " & _
"" & marr & ",'" & Me.txtaddress.Text.Trim & "'," & Me.txtpostalcode.Text.Trim & ", " & _
"'" & Me.txtEmail.Text.Trim & "'," & Me.txtphone.Text.Trim & ", " & _
"" & Me.txtidCard.Text.Trim & ",'" & Me.txtpost.Text.Trim & "', " & _
"'" & Me.txtduty.Text.Trim & "','" & Me.txtdutystatus.Text.Trim & "', " & _
"'" & Me.txtdepartment.Text.Trim & "','" & Me.txtfroeignlevel.Text.Trim & "', " & _
"'" & Me.txtlanguagetype.Text.Trim & "','" & Me.txtcomputerlevel.Text.Trim & "', " & _
"" & Me.txtbankcard.Text.Trim & ",'" & Me.txtbank.Text.Trim & "', " & _
"" & Me.txtsafetycard.Text.Trim & "," & Me.txtstartworkdate.Text.Trim & ", " & _
"" & Me.txtlengthservice.Text.Trim & "," & Me.txtpaylevel.Text.Trim & ", " & _
"" & Me.txtintime.Text.Trim & "," & Me.txtouttime.Text.Trim & ", " & _
"" & Me.txtownlengthservic.Text.Trim & "," & Me.txtstartworkdate.Text.Trim & ", " & _
"" & Me.txtendpactdate.Text.Trim & ")"
Try
con.Open()
com.ExecuteNonQuery()
con.Close()
MessageBox.Show("记录添加成功", "提示消息", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
MessageBox.Show("记录添加失败", "提示消息", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Exit Sub
End Try
End If