Ado和VB结合,高手请进,在线等!

ywxbutterfly 2003-08-18 04:00:19
我想做一个界面是登录用的,当用户登录时,我要先检查这个用户是否已经注册,即他是否已经存在数据库中了,那么我该怎么做?
最好给出原代码,谢谢!
因本人是笨人一个,对数据库操作很不懂,谢谢指导!
...全文
24 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ywxbutterfly 2003-08-18
  • 打赏
  • 举报
回复
谢谢各位!我的问题总算解决了。
道素 2003-08-18
  • 打赏
  • 举报
回复
将mConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName & ";Persist Security Info=False"
换成
mConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & strDBName & ";Persist Security Info=False"
试试,还有这个连接过程可以拿到这个函数外部,避免多次输入多次连接,不过还是先把这个通过在考虑
如果改成3.51还不行,我看你还是升级的ado吧
viena 2003-08-18
  • 打赏
  • 举报
回复
也可以
sUserName = Trim(txtUserName.Text)
rs.Find ("username='"& sUserName '")
if not rs.eof then
msgbox "该用户已存在"
end if

mdac_typ.exe
HZCNC 2003-08-18
  • 打赏
  • 举报
回复
If textUserName.Text = "" Then Exit Sub
Dim cnt As ADODB.Connection
Set cnt = New ADODB.Connection
cnt.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & txtUserName & " ;PASSWORD = " & txtPassword & " ;Initial Catalog=" & txtDataBase & ";Data Source=" & txtServer
Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM UserName where username = '" & textUserName.Text & "'", cnt, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox "该用户不存在,再试一次!", vbOKOnly Or vbExclamation, "登录"
textUserName.SetFocus
rs.Close
cnt.Close
Else
If StrComp(textPassword.Text, rs!Password) = 0 Then
constant.TureName = rs!TureName
Unload Me
frmMain.Show
rs.Close
cnt.Close
Else
MsgBox "密码错误,再试一次!", vbOKOnly Or vbExclamation, "登录"
textPassword = ""
textPassword.SetFocus
rs.Close
cnt.Close
End If
End If
lxcc 2003-08-18
  • 打赏
  • 举报
回复
升级你的MDACTYPE
也就是ADO版本
Alicky 2003-08-18
  • 打赏
  • 举报
回复
up
ywxbutterfly 2003-08-18
  • 打赏
  • 举报
回复
谢谢ch21st(风尘鸟),只是按照你的方法运行后,出现错误,显示在mconn.open,提示为:找不到可安装的isam,能否解决?谢谢!
winwindyx 2003-08-18
  • 打赏
  • 举报
回复
Private Sub cmdUserName_Click()
Dim str As String

If txtName.text <> "" Then
str = "select * from USERNAME where UserName='" & txtName & "'"
rs.Open str, con, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
...
Else
rs.close
...
End If
End If
End Sub
winwindyx 2003-08-18
  • 打赏
  • 举报
回复
Private Sub cmdUserName_Click()
Dim str As String

If txtName.text <> "" Then
str = "select * from USERNAME where UserName='" & txtName & "'"
rs.Open str, con, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
...
Else
re.close
...
End If
End If
End Sub
elfire 2003-08-18
  • 打赏
  • 举报
回复
在此代码之前连接数据库/




strSql = "SELECT * FROM 用户级别表 WHERE userid ='" & Trim(txtUser.Text) & "'"
'数据库查询
...

If objRs.RecordCount <> 0 Then

'操作员密码
If Trim(txtPWD.Text) = Trim(objRs!pwd) Then
'登录成功
else
'密码不正确
end if

else
'用户不存在
end if
objRs.Close
道素 2003-08-18
  • 打赏
  • 举报
回复
上面的代码有个很大的漏洞,就是没有释放资源
你实际写的时候别忘记释放,我只是示范方法
道素 2003-08-18
  • 打赏
  • 举报
回复
这个问题不需要高手,我就可以回答
Option Explicit

Public LoginSucceeded As Boolean
Dim mConn As New ADODB.Connection
Dim mRst As New ADODB.Recordset
Dim strDBName As String


Private Sub cmdCancel_Click()
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()
Dim sUserName As String
Dim strSQL As String
mConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName & ";Persist Security Info=False"
mConn.Open
sUserName = Trim(txtUserName.Text)
strSQL = "Select * from User where UserID='" & sUserName & "'"
mRst.Open strSQL, mConn, adOpenDynamic, adLockOptimistic
If mRst.EOF Then
MsgBox "没有该用户!", vbCritical
Exit Sub
Else
If txtPassword = mRst.Fields("password") Then
LoginSucceeded = True
Me.Hide
Else
MsgBox "密码错误,请重试!", vbCritical, "登陆"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End If

End Sub

Private Sub Form_Load()
strDBName = "C:\Test.mdb"
End Sub
zhenglc 2003-08-18
  • 打赏
  • 举报
回复
先建立数据库连接,然后在用户输入用户名后检查用户表

Private Sub txtLogName_LostFocus()
Dim csql As String

csql = "select * from T_USER where LogName='" & txtLogName & "'"

If rs.State = adStateOpen Then
rs.Close
End If
rs.Open csql, cn, adOpenKeyset, adLockOptimistic
If rs.RecordCount < 1 Then
...
Else
...
End If

End Sub

1,216

社区成员

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

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