这是VB连接SQL数据库的添加操作
我调试了很多次了 但是总是提示"在此上下文中不允许列名,只允许出现常量,变量或表达式
Private Sub Command1_Click()
Dim add As Booleanadd = TrueIf Trim(txtbh.Text) = "" Then
MsgBox "请输入编号", vbExclamation, "验证"
txtbh.SetFocus
Exit Sub
End If
If Trim(txtxsxm.Text) = "" Then
MsgBox "请输入姓名", vbExclamation, "验证"
txtxsxm.SetFocus
Exit Sub
End If
If Trim(txtxb.Text) = "" Then
MsgBox "请输入性别", vbExclamation, "验证"
txtxb.SetFocus
Exit Sub
End If
If Trim(txtcsrq.Text) = "" Then
MsgBox "请输入出生年月", vbExclamation, "验证"
txtcsrq.SetFocus
Exit Sub
End If
If Trim(txtjg.Text) = "" Then
MsgBox "请输入籍贯", vbExclamation, "验证"
txtjg.SetFocus
Exit Sub
End If
If Trim(txtmz.Text) = "" Then
MsgBox "请输入民族", vbExclamation, "验证"
txtmz.SetFocus
Exit Sub
End If
If Trim(txtsfzh.Text) = "" Then
MsgBox "请输入身份证号", vbExclamation, "验证"
txtsfzh.SetFocus
Exit Sub
End If
If Trim(txtzw.Text) = "" Then
MsgBox "请输入职务", vbExclamation, "验证"
txtzw.SetFocus
Exit Sub
End If
If Trim(txtjzdz.Text) = "" Then
MsgBox "请输入居住地址", vbExclamation, "验证"
txtjzdz.SetFocus
Exit Sub
End If
If Trim(txtxszh.Text) = "" Then
MsgBox "请输入学生证号", vbExclamation, "验证"
txtxszh.SetFocus
Exit Sub
End If
If Trim(txtyzbm.Text) = "" Then
MsgBox "请输入邮政编码", vbExclamation, "验证"
txtyzbm.SetFocus
Exit Sub
End If
If Trim(txtdh.Text) = "" Then
MsgBox "请输入联系电话", vbExclamation, "验证"
txtdh.SetFocus
Exit Sub
End If
If Trim(txtbz.Text) = "" Then
MsgBox "请输入备注", vbExclamation, "验证"
txtbz.SetFocus
Exit Sub
End If
If add Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student"
conn.Open
Set rs = conn.Execute("select * from 学生基本信息表 where student_id=" & txtbh.Text)
If Not rs.EOF Then
MsgBox ("此记录重复,请重新输入!")
Exit Sub
Else
conn.Execute ("insert into 学生基本信息表(student_id,student_xm,student_xb,student_sr,student_jg,student_mz,student_sfzh,student_zw,student_jzdz,student_xszh,student_yzbm,student_dh,student_bz) values(" & txtbh.Text & ",'" & txtxsxm.Text & "','" & txtxb.Text & "','" & txtcsrq.Text & "','" & txtjg.Text & "'," & txtmz.Text & "," & txtsfzh.Text & "," & txtzw.Text & "," & txtjzdz.Text & "," & txtxszh.Text & "," & txtyzbm.Text & "," & txtdh.Text & ",'" & txtbz.Text & "')")
MsgBox "数据添加成功!", vbInformation, "ADD"
End If
End If
End Sub
先在这里谢谢大家了,希望能帮忙解决这个问题!!!