将数据库中的pwd值取出来,在赋值给变量user_pwd 怎么办?
tcbo 2005-03-19 08:57:53 Option Explicit
Dim cnn As ADODB.Connection '连接
Dim mycommand As ADODB.Command '命令
Dim rstByQuery As ADODB.Recordset '结果集
Dim strCnn As String '连接字符串
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
'设置全局变量为 false
'不提示失败的登录
LoginSucceeded = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
Dim i As Integer
Dim user_pwd As String
Set cnn = New ADODB.Connection
Set mycommand = New ADODB.Command
cnn.CursorLocation = adUseClient
cnn.Open "PROVIDER=MSDASQL;dsn=card;uid=;pwd=;"
mycommand.ActiveConnection = cnn
mycommand.CommandType = adCmdText
mycommand.CommandText = "select pwd from student where user_id='" + txtUserName + '"
Set rstByQuery = New ADODB.Recordset
Set rstByQuery = mycommand.Execute()
'检查正确的密码
If txtPassword = user_pwd Then
'将代码放在这里传递
'成功到 calling 函数
'设置全局变量时最容易的
LoginSucceeded = True
MsgBox "succeeded"
Me.Hide
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
cnn.Close '关闭连接
Set cnn = Nothing '释放连接
End Sub