Probem with Checking the database

bharanidharanit

Well-known member
Joined
Dec 8, 2008
Messages
53
Location
India
Programming Experience
1-3
Hello,
I am doing Login Screen in VS2008.
When i logon with username and password in form it only checking the first field in database.
How to do coding for checking all the fields???
This is my coding
VB.NET:
Imports System.Data.OleDb
Public Class frmLogin
    Private connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db.mdb"
    Private conn As OleDb.OleDbConnection
    Private dr As OleDb.OleDbDataReader


    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New OleDbConnection(connstring)
        conn.Open()
    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Dim cmd As New OleDbCommand("select * from login", conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr(0) = txtUser.Text And dr(1) = txtPwd.Text Then
            Form2.Show()
        Else
            txtUser.Clear()
            txtPwd.Clear()
            txtUser.Focus()
        End If
    End Sub
End Class
 
You could try using a while statement for the read as in:

VB.NET:
While dr.Read()

'Process login

End While
 
this worked for me
VB.NET:
Dim cmd As New OleDbCommand("select * from login where id= '"+txtUser.Text+"' and pass='"+txtPwd.Text+"'", conn)
        dr = cmd.ExecuteReader
        if(dr.HasRows)
            Form2.Show()
        Else
            txtUser.Clear()
            txtPwd.Clear()
            txtUser.Focus()
        End If
 
Back
Top