分析 源码,求助

dwh0722 2003-03-25 01:44:08
我做了一个登陆界面,有点问题。数据库为name=11,password=11,第一次输入11,12,告诉我“密码错误”,接着输入11、11,程序提示出错。
代码:(如何解决)
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
If Trim(txtName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
ElseIf txtPwd.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Else
rst.Open ("Select * from login where Name='" & Trim(txtName.Text) & "'")

If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtPwd.Text = ""
Else
If Trim(rst.Fields(1)) = Trim(txtPwd.Text) Then
MsgBox ("ok")
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
End If
End If
End If
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db3.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub

Private Sub Cmdexit_Click()
End
End Sub
...全文
5 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chenyu5188 2003-03-25
Dim con As adodb.Connection
Dim rst As adbodb.Recordset
Private Sub cmdOK_Click()
If Trim(txtName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
ElseIf txtPwd.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Else
rst.Open ("Select * from login where Name='" & Trim(txtName.Text) & "'")

If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtPwd.Text = ""
Else
If Trim(rst.Fields(1)) = Trim(txtPwd.Text) Then
MsgBox ("ok")
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
End If
End If
End If
rst.close'***************
set rst=nothing'*************
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db3.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub

Private Sub Cmdexit_Click()
End
End Sub


第一次你运行程序没有问题,第二次因为你再次执行了rst.open语句,也就是重复打开数据库,在不关闭的情况下你再次再开就会产生错误。
回复
dwh0722 2003-03-25
sxs69() 对不起你来迟了
回复
dwh0722 2003-03-25
谢谢,我以后还要问许多问题的,因为我在做生产实习
回复
sxs69 2003-03-25
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
If Trim(txtName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
ElseIf txtPwd.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Else
rst.Open ("Select * from login where Name='" & Trim(txtName.Text) & "'")

If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtPwd.Text = ""
Else
If Trim(rst.Fields(1)) = Trim(txtPwd.Text) Then
MsgBox ("ok")
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPwd.Text = ""
End If
End If

rst.Close '加这一代码,因为不允许重复打开数据库

End If
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db3.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub

Private Sub Cmdexit_Click()
End
End Sub
回复
pcwak 2003-03-25
行了没有
回复
dwh0722 2003-03-25
where?
回复
pcwak 2003-03-25
上面那个错了
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
If Trim(txtName.Text = "") Then
MsgBox "姓名不能为空", vbOKOnly + vbExclamation, "警告"
txtpwd.Text = ""
Exit Sub
End If
If txtpwd.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If

rst.Open ("Select * from qq where 用户='" & Trim(txtName.Text) & "'")
If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtpwd.Text = ""
Else
If Trim(rst.Fields(1)) = Trim(txtpwd.Text) Then
MsgBox ("ok")
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtpwd.Text = ""
End If
End If
rst.Close
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db3.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub

Private Sub Cmdexit_Click()
End
End Sub
回复
dwh0722 2003-03-25
是3705,刚才写错了
回复
pcwak 2003-03-25
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
If Trim(txtName.Text = "") Then
MsgBox "姓名不能为空", vbOKOnly + vbExclamation, "警告"
txtpwd.Text = ""
Exit Sub
End If
If txtpwd.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If

rst.Open ("Select * from login where Name='" & Trim(txtName.Text) & "'")
If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtpwd.Text = ""
Else
If Trim(rst.Fields(1)) = Trim(txtpwd.Text) Then
MsgBox ("ok")
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtpwd.Text = ""
End If
End If

End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db3.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub

Private Sub Cmdexit_Click()
End
End Sub


回复
dwh0722 2003-03-25
rst.Open ("Select * from login where Name='" & Trim(txtName.Text) & "'")
实时错误"3075"对象打开时操作不被允许
回复
pcwak 2003-03-25
什么错误
回复
dwh0722 2003-03-25
都是源代码呀
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-03-25 01:44
社区公告
暂无公告