vb+access的数据库保存新录入的员工信息提示日期时间语法错误
增加新员工部分代码,麻烦帮忙看看。。提示日期时间语法错误Private Sub cmdAdd_click()
Dim strSQL2 As String, strSex As String, i As Integer
cmdDel.Enabled = False
If cmdAdd.Caption = "增加" Then
Status (True)
bAdd = True '增加状态
ClearData '清除数据
cmdAdd.Caption = "保存"
cmdAdd.Enabled = False
cmdCancel.Enabled = True
txtName.SetFocus
ElseIf cmdAdd.Caption = "修改" Then
Status (True)
cmdCancel.Enabled = True
cmdAdd.Caption = "保存"
cmdAdd.Enabled = False
ElseIf cmdAdd.Caption = "保存" Then
If bAdd Then '增加员工数据
If CheckData() = False Then Exit Sub '检查用户输入或修改的数据
strSQL2 = "INSERT INTO 职员表(姓名,部门,性别,身份证,入职时间,职务,职称,基本工资,备注) "
strSQL2 = strSQL2 & "VALUES('" & txtName.Text & "'," '姓名
strSQL2 = strSQL2 & cmbDept.ItemData(cmbDept.ListIndex) & ",'" '部门
If optMan.Value Then
strSex = "男"
Else
strSex = "女"
End If
strSQL2 = strSQL2 & strSex & "','" '性别
strSQL2 = strSQL2 & txtID.Text & "',#" '身份证
strSQL2 = strSQL2 & dtpDate.Value & ",#" '入职时间"
strSQL2 = strSQL2 & cmbJob.ItemData(cmbJob.ListIndex) & "," '职务
strSQL2 = strSQL2 & cmbPro.ItemData(cmbPro.ListIndex) & "," '职称
strSQL2 = strSQL2 & Val(txtBasePay.Text) & ",'" '基本工资
strSQL2 = strSQL2 & txtMemo.Text & "')" '备注
SQLExt (strSQL2)
bAdd = False
Else '更新数据
strSQL2 = "UPDATE [职员表] SET 姓名='" & txtName.Text & "',"
If cmbDept.ListIndex >= 0 Then strSQL2 = strSQL2 & "部门 = " & cmbDept.ItemData(cmbDept.ListIndex) & ","
If optMan.Value Then
strSex = "男"
Else
strSex = "女"
End If
strSQL2 = strSQL2 & "性别 = '" & strSex & "',"
strSQL2 = strSQL2 & "身份证 = '" & txtID.Text & "',"
strSQL2 = strSQL2 & "入职时间 = #" & dtpDate.Value & "#,"
If cmbJob.ListIndex >= 0 Then strSQL2 = strSQL2 & "职务 = " & cmbJob.ItemData(cmbJob.ListIndex) & ","
If cmbPro.ListIndex >= 0 Then strSQL2 = strSQL2 & "职称 = " & cmbPro.ItemData(cmbPro.ListIndex) & ","
strSQL2 = strSQL2 & "基本工资 = " & Val(txtBasePay.Text) & ","
strSQL2 = strSQL2 & "备注 =' " & txtMemo.Text & "' "
strSQL2 = strSQL2 & "WHERE ID=" & iID
SQLExt (strSQL2)
End If
Adodc1.Refresh
DataGrid1.Columns(0).Visible = False
ClearData
Status (False)
cmdAdd.Caption = "增加"
cmdCancel.Enabled = False
End If
End Sub
代码要清楚,将字段值两边要加的 ' # 等写在一起,不要混淆。
strSQL2 = strSQL2 & "'" & txtID.Text & "'," '身份证还是不行哦。。还是提示操作符丢失。。。
strSQL2 = strSQL2 & "#" & dtpDate.Value & "#," '入职时间"
Debug.Print strSQL2 '<- 直接检查最终的 SQL-,-找不出来啊。。急死了。。 谁能帮帮看看程序啊。。 strSQL2 = strSQL2 & dtpDate.Value & ",#" '入职时间"
SQLExt (strSQL2)
改成:
strSQL2 = strSQL2 & dtpDate.Value & "#," '入职时间"
补充:VB , 数据库(包含打印,安装,报表)