level 7
深邃的爱🍀
楼主
Option Explicit
Dim SQL As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Image2_Click() '点击登录
If Text1.Text = "" Then
MsgBox "用户名不能为空"
Text1.SetFocus
Else
If conn.State = 0 Then '判断是否连接数据库
conn.ConnectionString = "Provider=SQLOLEDB.1;Password=320721;Persist Security Info=True;User ID=sa;Initial Catalog=SZC;Data Source=192.168.0.168" '数据库链接字串符
conn.Open '建立链接
Else
SQL = "select * from admin where username = '" & Text1.Text & "' and password ='" & Text2.Text & "' " '获取账号密码记录
Set rs = New ADODB.Recordset
rs.Open SQL, conn, adOpenKeyset, adLockOptimistic
If rs.BOF = False Then
MsgBox "登录成功"
Else
rs.Close
SQL = "select * from admin where username = '" & Text1.Text & "' " '获取账号
rs.Open SQL, conn, adOpenKeyset, adLockOptimistic
If rs.BOF = True Then MsgBox "用户不存在"
If rs.BOF = False Then MsgBox "密码错误"
End If
End If
End If
2021年12月14日 05点12分
1
Dim SQL As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Image2_Click() '点击登录
If Text1.Text = "" Then
MsgBox "用户名不能为空"
Text1.SetFocus
Else
If conn.State = 0 Then '判断是否连接数据库
conn.ConnectionString = "Provider=SQLOLEDB.1;Password=320721;Persist Security Info=True;User ID=sa;Initial Catalog=SZC;Data Source=192.168.0.168" '数据库链接字串符
conn.Open '建立链接
Else
SQL = "select * from admin where username = '" & Text1.Text & "' and password ='" & Text2.Text & "' " '获取账号密码记录
Set rs = New ADODB.Recordset
rs.Open SQL, conn, adOpenKeyset, adLockOptimistic
If rs.BOF = False Then
MsgBox "登录成功"
Else
rs.Close
SQL = "select * from admin where username = '" & Text1.Text & "' " '获取账号
rs.Open SQL, conn, adOpenKeyset, adLockOptimistic
If rs.BOF = True Then MsgBox "用户不存在"
If rs.BOF = False Then MsgBox "密码错误"
End If
End If
End If