Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim SQL As String
Dim RS As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = " Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=sa;Initial Catalog=db_DY;Data Source=NIE"
RS.CursorLocation = adUseClient
' RS.CursorType = adOpenStatic
cn.Open
If Trim(Text1.Text) <> "" Then
SQL = "SELECT * FROM tb_userinfo WHERE userid='" & Trim(Text1.Text) & "'"
Set RS = cn.Execute(SQL)
If RS.RecordCount > 0 Then
If Text2.Text = RS!pwd Then
MsgBox "登錄成功!"
End If
Else
MsgBox "登錄名錯誤,請確認"
Text1.Text = " "
End If
Else
MsgBox "請輸入用戶名"
End If
cn.Close
Set cn = Nothing
End Sub
uj5u.com熱心網友回復:
cn.Execute 會自動新建一個RecordSet實體,你前面 RS.CursorLocation = adUseClient 毫無用處。要么設 cn.CursorLocation = adUseClient
要么用 rs.Open() 函式查詢。
uj5u.com熱心網友回復:
'這樣試試:SQL = "SELECT * FROM tb_userinfo WHERE userid='" & Trim(Text1.Text) & "'"
if rs.state<>adstateclosed then rs.close
rs.open sql,cn,adopenkeyset,adlockreadonly
if rs.recordcount>0 then
....
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/108077.html
