+ Reply to Thread
Results 1 to 5 of 5

Thread: simple log in program with database access

  1. #1
    ogimy is offline VB.NET Forum Newbie ogimy is on a distinguished programming path ahead
    .NET Framework
    .NET 4.0
    Join Date
    Mar 2010
    Age
    20
    Posts
    9
    Reputation
    0

    Default simple log in program with database access

    i have make the simple code log in program with connect database.The below code have something problem.Can someone pro solve the problem.


    Private Sub btnSignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignIn.Click
    Dim conn As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim command As New OleDb.OleDbCommand

    conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Prokiller\My Documents\Visual Studio Projects\in process\New Folder (2)22\username.mdb"

    conn.Open()
    command.CommandText = "SELECT * FROM [UserName] WHERE TblUserName'" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"
    command.Connection = conn

    da.SelectCommand = command
    da.Fill(ds, "username")

    Dim count = ds.Tables(0).Rows.Count

    If count > 0 Then
    MsgBox("ok")
    Form2.Show()
    Me.Hide()
    Else
    MsgBox("invalid")

    End If

    conn.Close()
    End Sub

  2. #2
    Tom
    Tom is offline VB.NET Forum Idol Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2005
    Posts
    746
    Reputation
    340

    Default

    =
    .........

  3. #3
    r3plica's Avatar
    r3plica is offline VB.NET Forum Enthusiast r3plica done a little coding in his/her time r3plica done a little coding in his/her time r3plica done a little coding in his/her time
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2010
    Age
    30
    Posts
    81
    Reputation
    63

    Default

    yeah Tom is right, you are missing the = but you have also said the column rather than the table

    Code:
    command.CommandText = "SELECT * FROM [UserName] WHERE TblUserName'" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"
    It should be

    Code:
    command.CommandText = "SELECT * FROM TblUserName WHERE [UserName] = '" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"
    or better still

    Code:
    command.CommandText = "SELECT * FROMFROM TblUserName WHERE UPPER([UserName]) LIKE '%" & txtUserName.Text.ToUpper & "%' AND UPPER(Pin) LIKE '%" & txtPin.Text.ToUpper & "%';"
    If I solve your issue or you are happy with my response, please provide me with reputation by clicking the reputation link at the top right of my posts - thanks

  4. #4
    ogimy is offline VB.NET Forum Newbie ogimy is on a distinguished programming path ahead
    .NET Framework
    .NET 4.0
    Join Date
    Mar 2010
    Age
    20
    Posts
    9
    Reputation
    0

    Smile

    easy mistake.very hard to find it.sorry i newbie thank
    Last edited by ogimy; 03-18-2010 at 11:08 AM.

  5. #5
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    Quote Originally Posted by ogimy
    easy mistake.very hard to find it.
    It's only hard to see because you made it so by complicating the code, parameterize the query:
    Code:
    .CommandText = "SELECT * FROM TblUserName WHERE [UserName] = @UserName AND Pin= @Pin"
    .Parameters.AddWithValue("@UserName", txtUserName.Text)
    .Parameters.AddWithValue("@Pin", txtPin.Text)
    Other benefits include for example avoiding SQL injection.
    Further recommendations: Data Walkthroughs and/or Forms over Data Video Series

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts