有一个问题。。。

yuanboailanqiu 2009-12-16 03:06:12
Private Sub Command1_Click()
Dim mrc As New ADODB.Recordset
'txtsql = " select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' "
txtsql = " select * from oper where 用户名= '1111' and 口令= '1111' "

'Text2.Text = txtsql
Set mrc = exesql(txtsql)
If mrc.RecordCount = 0 Then '未找到用户记录
n = n + 1
If n < 3 Then
MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示"
Text1(0).Text = ""
Text1(1).Text = ""
Text1(0).SetFocus
Else
MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示"
mcr.Close
Unload Me
End If
Else '找到合法用户
userlevel = Trim(mrc.Fields("级别"))
mrc.Close
Unload Me
menu.Show '调用主界面窗体
End If
End Sub
调试时老说没有用户什么什么的。。。小菜鸟 有点郁闷啊。。。
...全文
120 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2009-12-16
  • 打赏
  • 举报
回复
http://download.csdn.net/source/1498324
这是我常用的操作数据库的代码,你看看对你有用否。
贝隆 2009-12-16
  • 打赏
  • 举报
回复
试一试这段代码,根据你提供的原始代码修改的。
Private Sub Command1_Click() 
Dim mrc As New ADODB.Recordset
'txtsql = " select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' "
txtsql = " select * from oper where 用户名= '1111' and 口令= '1111' "

'Text2.Text = txtsql
Set mrc = exesql(txtsql)
If mrc.eof or mrc.bof Then '未找到用户记录
n = n + 1
If n < 3 Then
MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示"
Text1(0).Text = ""
Text1(1).Text = ""
Text1(0).SetFocus
Else
MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示"
mcr.Close
Unload Me
End If
Else '找到合法用户
userlevel = Trim(mrc.Fields("级别"))
mrc.Close
Unload Me
menu.Show '调用主界面窗体
End If
End Sub
king06 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 yuanboailanqiu 的回复:]

  If mrc.RecordCount = 0 Then '未找到用户记录? 这就算没有该用户了? 说不定是密码没输入正确,用户还是有的啊
[/Quote]
给你一个参考下思路吧
Dim micount As Integer
Private Sub Command1_Click()
Dim txtSql As String
Dim mrc As ADODB.Recordset
Dim msgtext As String
UserName = "" '这是个全局变量

If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSql = "select * from financer where 用户名='" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSql, msgtext) '这个ExecuteSQL也是个自定义的函数
If mrc.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(mrc.Fields("密码")) = Trim(txtpassword.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtpassword.SetFocus
txtpassword.Text = ""
End If
End If
End If

micount = micount + 1
If micount = 3 Then
Me.Hide
End If
End Sub
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
恩恩。。。咋就那么郁闷了捏》》
jhone99 2009-12-16
  • 打赏
  • 举报
回复
mrc.Close 这一句?
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
实时错误‘424’
要求对象
jhone99 2009-12-16
  • 打赏
  • 举报
回复
什么错误提示?
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
还是没用的捏。。大虾帮帮忙的啊 。。小弟做课程设计都急死了饿
Private Sub Command1_Click()
Dim mrc As New ADODB.Recordset
'txtsql = " select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' "
txtsql = " select * from oper where 用户名= '1111' and 口令= '1111' "

'Text2.Text = txtsql
Set mrc = exesql(txtsql)
If mrc.RecordCount = 0 Then '未找到用户记录
n = n + 1
If n < 3 Then
MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示"
Text1(0).Text = ""
Text1(1).Text = ""
Text1(0).SetFocus
Else
MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示"
mcr.Close
Unload Me
End If
Else '找到合法用户
userlevel = Trim(mrc.Fields("级别"))
mrc.Close 还显示这里有问题的啊
Unload Me
menu.Show '调用主界面窗体
End If
End Sub
jhone99 2009-12-16
  • 打赏
  • 举报
回复
Public Function exesql(ByVal sql As String) As ADODB.Recordset ' 用于执行SELECT语句
sql = Trim$(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "dsn=KS;uid=MICROSOF-45B405;pwd=;"
conn.Open
Set rst.ActiveConnection = conn
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open sql
Set exesql = rst
Set rst = Nothing '释放记录
Set conn = Nothing '释放连接

End Function
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
Public Function exesql(ByVal sql As String) As ADODB.Recordset ' 用于执行SELECT语句
sql = Trim$(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "dsn=KS;uid=MICROSOF-45B405;pwd=;"
conn.Open
Set rst.ActiveConnection = conn
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open sql
Set exesql = rst
Set exesql = Nothing '释放记录
Set conn = Nothing '释放连接

End Function
第一句是不是啊 。。。
jhone99 2009-12-16
  • 打赏
  • 举报
回复
exesql()函数的代码呢?看这个是否有问题
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
那是咋回事的啊?
guyehanxinlei 2009-12-16
  • 打赏
  • 举报
回复
UP
yuanboailanqiu 2009-12-16
  • 打赏
  • 举报
回复
恩恩 。。。。是的啊 数据库里有数据的啊 可以注册添加进去 可是就是不能登录到下一个界面 就一直弹出那个没有该用户,继续登录的对话框,,。。郁闷。。
jhone99 2009-12-16
  • 打赏
  • 举报
回复
没有该用户,继续登陆
****************

这个吗?没有数据吧

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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