Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim cmd As New
If Text1.Text = "" Then
MsgBox "用户名不能为空!"
Text1.SetFocus
Exit Sub
Else
Call ConToSQLDB
cmd.ActiveConnection = sqlcon
= "select * from yhxx where 用户名='" & Text1.Text & "'"
Set rs = cmd.Execute
If rs.EOF Then
MsgBox "用户不存在!"
rs.Close
sqlcon.Close
Text1.SetFocus
Exit Sub
ElseIf rs!密码 <> Text2.Text Then
MsgBox "密码不正确!"
rs.Close
sqlcon.Close
Text2.SetFocus
Exit Sub
Else
caozuoyuan = Text1.Text
rs.Close
Set rs = Nothing
sqlcon.Close
Unload Me
Form1.Show
End If
End If
End Sub
'================================================================
' 下面这个新建一个模块放在里.我喜欢这样,什么时候调用都行.
Function ConToSQLDB()
'*******************************
'打开与 SQL Server 数据库的连接
'*******************************
sqlcon.Provider = "sqloledb"
sqlcon.Properties("Data Source").Value = "ADMIN"
'//
ADMIN为SQL Server 服务器名
sqlcon.Properties("Initial Catalog").Value = "tempdata"
'//tempdata 为已创建数据库名
sqlcon.Properties("Integrated Security").Value = "SSPI"
sqlcon.Properties("persist security info").Value = "False"
sqlcon.Properties("user id").Value = "sa"
sqlcon.Properties("password").Value = "sa"
sqlcon.Open
End Function