分析 源码,求助

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
...全文
40 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
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
  • 打赏
  • 举报
回复
都是源代码呀

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧