标题:如何向ACCESS数据库添加记录
只看楼主
lij40
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-5-4
 问题点数:0 回复次数:0 
如何向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
帮帮我吧,谢谢!

搜索更多相关主题的帖子: 数据库 ACCESS 记录 
2007-05-04 19:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-136898-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.200273 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved