VB+SQL登陆代码问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 21:41:16
Public conn As ADODB.Connection
Sub main()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=ss"
conn.Open
登陆首页.Show '登录界面
End Sub

再在登录界面“确定”下写入如下代码:
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
Text2.SetFocus
Exit Sub
End If

Dim strSQl As String
strSQl = "select * from 用户表 where 用户名='" & Trim$(Text1.Text) & "' and 密码='" & Trim$(Text2.Text) & "' "

Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQl, conn, adOpenSt

我初学、不过我有在网上下载的一个源码的图书管理数据库也是vb+sql的里面这段代码发出来给你希望对你有帮助
Private Sub cmdOK_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\database.mdb"

If Trim(Text1.Text) = "" Then
MsgBox "用户名不能为空,请重新输入!"
Text1.SetFocus
Else
sql = "select * from 用户表 where user_ID='" & Trim(Text1.Text) & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户,请重输入!", vbOKOnly + vbExclamation, ""
Text1.Text = ""
Text1.SetFocus
Else
username = Text1.Text
If Trim(rs_login.Fields(1)) = Trim(Text2.Text) Then

Unload Me
图书馆理系统.Show
Else
MsgBox "密码不正确,请重输入