Home > Software engineering >  Just learning vb database connection, the execution, RS. RecordCount always to 1, according to onlin
Just learning vb database connection, the execution, RS. RecordCount always to 1, according to onlin

Time:10-03

Private Sub Command1_Click ()
Dim cn As ADODB. Connection
Dim As SQL String
Dim the RS As the ADODB library you
Set the cn=New ADODB. Connection
Cn. The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=True; User ID=sa; Password=sa; Initial Catalog=db_DY; Data Source=NIE "

RS. CursorLocation=adUseClient
'the RS. CursorType=adOpenStatic
Cn. Open
If the Trim (Text1. Text) & lt;> "" Then
SQL="SELECT * FROM tb_userinfo WHERE userid='" & amp; Trim (Text1. Text) & amp; "'
"Set the RS=cn. The Execute (SQL)
If the RS. RecordCount & gt; 0 Then
If Text2. Text=RS! The PWD Then
MsgBox "login successful!"
End the If
The Else
MsgBox "login error, please make sure the"
Text1. Text=""
End the If
The Else
MsgBox "please enter the user name"
End the If
Cn. Close
The Set cn=Nothing
End Sub

CodePudding user response:

Cn. The Execute will automatically create a new instance you, in front of you RS. CursorLocation=adUseClient useless,
Either a cn. CursorLocation=adUseClient
Either use rs. The Open () function queries,

CodePudding user response:

'try it like this:
SQL="SELECT * FROM tb_userinfo WHERE userid='" & amp; Trim (Text1. Text) & amp; "'
"If the rs. State<> Adstateclosed then rs. Close
Rs. The open SQL, cn, adopenkeyset, adlockreadonly
If the rs. Recordcount> 0 then
.
  • Related