如何向ACCESS数据库添加记录
请教高手 高手帮忙看看下面这段程序,功能是往数据库的表里添加记录,可是点了确定之后却没有反应
Private Sub cmdok_Click()
Dim dbuser As String
Dim usrpsw As String
dbuser = Texaddu.Text
usrpsw = Texaddp.Text
Set conn = New ADODB.Connection
conn.ConnectionString = "DSN=DBproject;DRIVER=Microsoft Access Driver(*.mdb);User ID=admin;Password=admin"
conn.Open
If Texaddu.Text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "提示"
Texaddu.SetFocus
Exit Sub
End If
If Texaddp.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "提示"
Texaddp.SetFocus
Exit Sub
End If
Dim strSQl As String
strSQl = "select * from user where 用户名=" & " '" & dbuser & " '" & "and 密码 = " & "'" & usrpsw & "'"
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQl, conn, adOpenStatic, adLockOptimistic
If Not (str.EOF And str.BOF) Then
str.MoveFirst
str.MoveLast
If Texaddp.Text = str.Fields("密码") And Texaddu.Text = str.Fields("用户名") Then
MsgBox "该用户已存在", vbCritical + vbOKOnly, "提示"
Texaddp.Text = ""
Texaddu.Text = ""
Else
str.AddNew
str.Fields("用户名") = Trim$(Texaddu.Text)
str.Fields("密码") = Trim$(Texaddp.Text)
str.Fields("职位") = Trim$(Texz.Text)
str.Update
MsgBox "添加成功", vbCritical + vbOKOnly, "提示"
End If
End If
End Sub
帮帮我吧,谢谢!