一段ADO连接access数据库添加数据的代码,不知道哪错了。
Dim sc As IntegerIf Not Testtxt(txtNo.Text) Or Testtxt(txtName.Text) Or Testtxt(txtSex.Text) Or Testtxt(txtBookTime.Text) Or Testtxt(txtTel.Text) Or Testtxt(txtEnrolTime.Text) Then
MsgBox "带 * 号为必填项", vbOKOnly + vbExclamation, "警告"
txtNo.SetFocus
Exit Sub
End If
sc = MsgBox("确实要添加这条记录吗?", vbOKCancel, "提示信息")
If sc = 1 Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=/data.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = "select * from 预约者"
rs.Open strSQL, conn, 3, 3
rs.AddNew
rs!编号 = txtNo.Text
rs!姓名 = txtName.Text
rs!性别 = txtSex.Text
rs!所在学院 = txtCollege.Text
rs!所在专业 = txtSpeciality.Text
rs!联系电话 = txtTel.Text
rs!预约时间 = txtBookTime.Text
rs!登记时间 = txtEnrolTime.Text
rs!备注 = txtRemark.Text
rs.Update
rs.Close
conn.Close
MsgBox ("添加记录成功!")
Adodc1.Refresh
End If
txtNo.Text = ""
txtName.Text = ""
txtSex.Text = ""
txtCollege.Text = ""
txtSpeciality.Text = ""
txtTel.Text = ""
txtBookTime.Text = ""
txtEnrolTime.Text = ""
txtRemark.Text = ""
End Sub
运行后,总是提示“带 * 号为必填项”,而不会执行下面的语句。