Probem with Checking the database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 117
Reputation: bharanidharanit is an unknown quantity at this point 
Solved Threads: 2
bharanidharanit bharanidharanit is offline Offline
Junior Poster

Probem with Checking the database

 
0
  #1
May 7th, 2009
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
  1. Imports System.Data.OleDb
  2. Public Class frmLogin
  3. Private connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db.mdb"
  4. Private conn As OleDb.OleDbConnection
  5. Private dr As OleDb.OleDbDataReader
  6.  
  7.  
  8. Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9. conn = New OleDbConnection(connstring)
  10. conn.Open()
  11. End Sub
  12.  
  13. Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
  14. Dim cmd As New OleDbCommand("select * from login", conn)
  15. dr = cmd.ExecuteReader
  16. dr.Read()
  17. If dr(0) = txtUser.Text And dr(1) = txtPwd.Text Then
  18. Form2.Show()
  19. Else
  20. txtUser.Clear()
  21. txtPwd.Clear()
  22. txtUser.Focus()
  23. End If
  24. End Sub
  25. End Class
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 192
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 24
jbisono's Avatar
jbisono jbisono is offline Offline
Junior Poster

Re: Probem with Checking the database

 
0
  #2
May 7th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 117
Reputation: bharanidharanit is an unknown quantity at this point 
Solved Threads: 2
bharanidharanit bharanidharanit is offline Offline
Junior Poster

Re: Probem with Checking the database

 
0
  #3
May 14th, 2009
thanks jbisono that worked
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC