943,619 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 546
  • VB.NET RSS
May 7th, 2009
0

Probem with Checking the database

Expand Post »
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 Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 8
Solved Threads: 3
Junior Poster
bharanidharanit is offline Offline
140 posts
since Nov 2008
May 7th, 2009
0

Re: Probem with Checking the database

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
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
431 posts
since May 2009
May 14th, 2009
0

Re: Probem with Checking the database

thanks jbisono that worked
Reputation Points: 8
Solved Threads: 3
Junior Poster
bharanidharanit is offline Offline
140 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Multiform view inside a formview inside a repeater control
Next Thread in VB.NET Forum Timeline: Array with radiobuttons





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC