hi ,

i given code for password validation which retrieve the data from oracle table.... it was validating the first record alone... its not validating the next records... help me to validate ...

...............

Option Explicit
Dim ac As New ADODB.Connection
Dim rs As New ADODB.Recordset



Private Sub Command1_Click()

If rs.Fields(0) = Text1.Text And rs.Fields(1) = Text2.Text Then
nsgbox " password is correct"
Form2.Show
End If

End Sub

Private Sub Form_Load()
ac.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=yp"
rs.Open "select * from demo", ac, adOpenDynamic, adLockOptimistic, -1
End Sub

Recommended Answers

All 9 Replies

In command1_click do a FOR loop until rs.EOF()

or

open recordset in command1_click event and in SQL syntax check for password and username but beware of SQL Injection

try this sample

select count(*) from demo where user_name = u_name and password = pwd

if this SQL returns 1 log in successful and proceed further
else
re-prompt for username / password.

No need of any looping or checking for EOF.

i modified your code for work correctly but i dont know you field name so im putting here username and password you can change these with yours one

..............

Option Explicit
Dim ac As New ADODB.Connection
Dim rs As New ADODB.Recordset



Private Sub Command1_Click()
if rs.state=adstateopen then rs.close
rs.Open "select * from demo where username='" & text1.text & "'", ac, adOpenDynamic, adLockOptimistic, -1
if rs.recordcount=1 then
if rs!password=text2.text then
nsgbox " password is correct"
Form2.Show
else
msgbox "Invalid Password"

endif
else
msgbox "Username Not Found"
End If

End Sub

Private Sub Form_Load()
ac.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=yp"

End Sub

see if this help :

Option Explicit
Dim ac As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Command1_Click()
Set rs = Nothing
rs.Open "select * from demo", ac, adOpenDynamic, adLockOptimistic, -1
If rs!UserName = Text1.Text Then ' modified as your user name field name
    If !rs.Password = Text2.Text Then ' modified as your password field name
        MsgBox " password is correct"
        Form2.Show
    Else
        MsgBox " wrong password "
    End If
Else
     MsgBox " user name unregistered "
End If

End Sub

Private Sub Form_Load()
ac.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=yp"
End Sub
commented: so nice!! +4

Jx_Man if you open recordset in command click event it should be first check its open or closed then first close it and then open it. other wise u can open a recordset once its already open if user click command button more than once it will get error.

@trilok31

Read line #6 of Jx_Man's code

oops i missed that sorry....

thanks for all for your valuable replies.....
i myself solved the problem ... it's working fine .... i attach my code here....

Option Explicit
Dim ac As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim ac1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset

Private Sub Command1_Click()

 ac1.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=yp"
 rs1.Open "select * from demo where username= " & "'" & Text1.Text & "'", ac1, adOpenDynamic, adLockOptimistic
 
 If rs1.BOF = False Then
 If Val(rs1.Fields(0)) = Val(Text1.Text) And Val(rs1.Fields(1)) = Val(Text2.Text) Then
 rs1.MoveNext
 MsgBox "valib"
 Me.Hide
 Form2.Show
 End If
 ElseIf rs1.BOF = True Then
 MsgBox "invalid"
 End If
 ac1.Close
 End Sub

Private Sub Form_Load()

ac.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=yp"
rs.Open "select * from demo", ac, adOpenDynamic, adLockOptimistic, -1

End Sub

Happy to learn your issue is solved.

Happy coding. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.