1个回答
展开全部
连接数据库简单的登录 代码如下
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim loginflag As Boolean
Private Sub Command1_Click()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
'建立无源数据库连接
conn.ConnectionString = "driver={sql server};server=12-3FDA18CE0DDC;uid=sa;pwd=sa;Database=test"
conn.ConnectionTimeout = 50
conn.Open
Dim str As String
'连接连接对象
Set rs.ActiveConnection = conn
'设置游标类型
rs.CursorType = adOpenDynamic
If Trim(Text1.Text = "") Then
MsgBox "用户名不能为空,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Else
'设置查询字符串
str = "select * from tt where name ='" & Trim(Text1.Text) & "'"
rs.Open str
If rs.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Else
'登录成功,连接主窗口
If (Trim(Text2.Text) = Trim(rs.Fields("password"))) Then
loginflag = True
Me.Hide
Form2.Show
MsgBox "登陆成功"
Else
MsgBox "密码不正确,请重输入密码!", , "警告"
Text2.SetFocus
SendKeys "{Home}+{End}"
End If
End If
End If
End Sub
Private Sub Command2_Click()
Me.Hide
loginflag = False
End
End Sub
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim loginflag As Boolean
Private Sub Command1_Click()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
'建立无源数据库连接
conn.ConnectionString = "driver={sql server};server=12-3FDA18CE0DDC;uid=sa;pwd=sa;Database=test"
conn.ConnectionTimeout = 50
conn.Open
Dim str As String
'连接连接对象
Set rs.ActiveConnection = conn
'设置游标类型
rs.CursorType = adOpenDynamic
If Trim(Text1.Text = "") Then
MsgBox "用户名不能为空,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Else
'设置查询字符串
str = "select * from tt where name ='" & Trim(Text1.Text) & "'"
rs.Open str
If rs.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Else
'登录成功,连接主窗口
If (Trim(Text2.Text) = Trim(rs.Fields("password"))) Then
loginflag = True
Me.Hide
Form2.Show
MsgBox "登陆成功"
Else
MsgBox "密码不正确,请重输入密码!", , "警告"
Text2.SetFocus
SendKeys "{Home}+{End}"
End If
End If
End If
End Sub
Private Sub Command2_Click()
Me.Hide
loginflag = False
End
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询