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

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

Hi,
I do not know if this can help but try it
replace dr(0) for dr.GetString(0) and dr.GetString(1).
also try in the select retrieve exact the two fields that you want, i do not know what is the structure of your table. if that does not work try this

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
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.