VS 2008 VB.NET getting login, and account info from .mdb (X64 Vista)

  • 10 years ago

    as you can si from the specifications I have a hard time using alot of the recources on the web to get my results correct, since alot of whats written are written for earlier versions of VS but i have been lucky until now. I now have a problem I really can't handle since I'm not a pro (yet).

     I need to get information from a .mdb file while whould do this:

    1. check all in the "username" column for username macthing "textbox1"

    2. then if it finds a matching username it will se if the "password" field on the same row are the same as "textbox2"

     I have found some OK code snippets that i modified to do what i want but they are in another "dialect", for want of a better word, and does not work.

     If anyone could help I whould be greatfull.

     thanks in advance!

  • 10 years ago

    You probably want something like this:

    (Obviously subsituting EXAMPLE.mdb with the full path to your database [e.g. c:\example.mdb] AND also putting in the correct table name instead of SOMETABLE.) 

     

            Dim oConnection As New Data.OleDb.OleDbConnection
            Dim oCommand As New Data.OleDb.OleDbCommand
            Dim oReader As Data.OleDb.OleDbDataReader

            oConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; data source=EXAMPLE.mdb"
            oCommand.Connection = oConnection
            oCommand.Connection.Open()
            oCommand.CommandText = "SELECT username, password FROM SOMETABLE"

            oReader = oCommand.ExecuteReader

            If oReader.HasRows Then
                While oReader.Read
                    If StrComp(oReader.Item("username"), TextBox1.Text, CompareMethod.Text) = 0 Then
                        If StrComp(oReader.Item("password"), TextBox2.Text, CompareMethod.Text) = 0 Then
                            MsgBox("Username and password match")
                        End If
                    End If
                End While
            Else
                MsgBox("No Data in table")
            End If

     

    You also might want to consider making the query:

    "SELECT username,password FROM SOMETABLE WHERE username =" & textbox1.text

     

  • 10 years ago

    [quote user="williamsg"]

    You probably want something like this:

    (Obviously subsituting EXAMPLE.mdb with the full path to your database [e.g. c:\example.mdb] AND also putting in the correct table name instead of SOMETABLE.) 

     

            Dim oConnection As New Data.OleDb.OleDbConnection
            Dim oCommand As New Data.OleDb.OleDbCommand
            Dim oReader As Data.OleDb.OleDbDataReader

            oConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; data source=EXAMPLE.mdb"
            oCommand.Connection = oConnection
            oCommand.Connection.Open()
            oCommand.CommandText = "SELECT username, password FROM SOMETABLE"

            oReader = oCommand.ExecuteReader

            If oReader.HasRows Then
                While oReader.Read
                    If StrComp(oReader.Item("username"), TextBox1.Text, CompareMethod.Text) = 0 Then
                        If StrComp(oReader.Item("password"), TextBox2.Text, CompareMethod.Text) = 0 Then
                            MsgBox("Username and password match")
                        End If
                    End If
                End While
            Else
                MsgBox("No Data in table")
            End If

     

    You also might want to consider making the query:

    "SELECT username,password FROM SOMETABLE WHERE username =" & textbox1.text

     

    [/quote]

    Thank you very much!!!!

    It did not work until I set VS to compile and debug to x86 processors, (some problem with the Microsoft.Jet.OLEDB.4.0 provider, it seems tha MS haven't made a x64 versieon yet)

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill