locked
creating login form in visual studio 2010 RRS feed

  • Question

  • Hi,

    i want to create a login form in vb using the visual studio 2010

    and i am using the following code:-

     

    Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=D:\ytcargo\ytcargo.mdb")

            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM User WHERE userid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "' ", con)

     

            con.Open()

            Dim dr As OleDbDataReader = cmd.ExecuteReader()

            If (dr.Read() = True) Then

                Dim m As New master

                m.Show()

                Me.Hide()

            Else

                MessageBox.Show("invalid password")

            End If

    but when ever i execute my project and click on login button i get this error

     

    " OledbException was unhandled"     syntex error in from clause 

     

    and it points to this particular line 

    Dim dr As OleDbDataReader = cmd.ExecuteReader()

    can any buddy please help in the same.

    Monday, November 29, 2010 6:38 PM

Answers

  • is your sql query correct ? check Table name.

    Thanks

    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    • Marked as answer by pk.yadav Tuesday, November 30, 2010 3:46 AM
    Monday, November 29, 2010 7:03 PM
  • Similar to the previous replies, but I believe what you need to do is this.

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [User] WHERE userid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'", con)

    Also,  are you sure you want to place "Dim m As New master" inside the if-block as  "m" will be destroyed after completion of the if-block.  No big deal if you have no need to reference it later.

    • Marked as answer by pk.yadav Tuesday, November 30, 2010 3:46 AM
    Monday, November 29, 2010 8:00 PM

All replies

  • I assume a scholar job as login is currently done by the environment, but your problem is that password is a protected name so you have to set it inside brackets.

      Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM User WHERE userid = '" & TextBox1.Text & "' AND [password] = '" & TextBox2.Text & "' ", con)

     

    (Not for PK at least I saw it quicker than Paul)

    :-)


    Success
    Cor
    Monday, November 29, 2010 6:58 PM
  • is your sql query correct ? check Table name.

    Thanks

    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    • Marked as answer by pk.yadav Tuesday, November 30, 2010 3:46 AM
    Monday, November 29, 2010 7:03 PM
  • Similar to the previous replies, but I believe what you need to do is this.

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [User] WHERE userid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'", con)

    Also,  are you sure you want to place "Dim m As New master" inside the if-block as  "m" will be destroyed after completion of the if-block.  No big deal if you have no need to reference it later.

    • Marked as answer by pk.yadav Tuesday, November 30, 2010 3:46 AM
    Monday, November 29, 2010 8:00 PM
  • This was what i used and it worked:

     

     

    Dim con As New OleDb.OleDbConnection

     

     

    Dim dbProvider As String

     

     

    Dim dbSource As String

     

    dbProvider =

     

    "PROVIDER=Microsoft.Jet.OLEDB.4.0;"

    dbSource =

     

    "Data Source = D:/AddressBook.mdb"

    con.ConnectionString = dbProvider & dbSource

     

     

    Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tblUsers WHERE username = '" & txtUserName.Text & "' AND password = '" & txtPassword.Text & "'", con)

    con.Open()

     

     

    Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()

     

     

     

    If (dr.Read() = True) Then

     

     

    Form1.Show()

     

     

    Me.Hide()

     

     

    Else

     

     

    MessageBox.Show("invalid password")

     

     

    End If

     

     

     

     

    End Sub

    Tuesday, December 7, 2010 8:02 PM