0

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
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by bharanidharanit
0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.