Click here to Skip to main content
12,502,578 members (54,886 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB Access VB.NET
Ok I got just one question that I can’t quite figure out.
Any and all help is much appreciated.

I am using VS 2010 and MS Access 2010.
The project that I am working on will include a MS Access database (\Database\DB.mdb)
The database will be mainly used to keep track on User information.

I have a Table (UserTable) and some Fields (ID, Username, Password, Active, Level, Notes)

The question is: How can I get the Level value by searching for the UserName?

Thanks for the read, hope you can help.


I was thinking something like:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

    Dim dbLevel As String
    Using connObj As New SqlClient.SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Database\DB.mdb; Jet OLEDB:Database Password=1qa@WS3ed$RF;") ' testing database
        Using cmdObj As New SqlClient.SqlCommand("select Level from UserTable where UserName = 'Test1'", connObj)
            Using readerObj As SqlClient.SqlDataReader = cmdObj.ExecuteReader
                'This will loop through all returned records
                While readerObj.Read
                    dbLevel = readerObj("Level").ToString
                    'handle returned value before next loop here
                End While
            End Using
        End Using
    End Using
    MessageBox.Show("Your variable is: " & dbLevel.ToString)
End Sub

But I cannot get it work as I do no know if: " Using cmdObj As New SqlClient.SqlCommand" is correct.
Posted 18-Dec-12 18:35pm
Updated 18-Dec-12 19:49pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Change your SELECT statement from what it is now to ....

Using cmdObj As New SqlClient.SqlCommand("select Level, Username from UserTable where UserName = 'Test1'", connObj)

And also the statement INSIDE the WHILE / END WHILE to....

dbLevel= readerObj.GetValue(readerObj.GetOrdinal("Level"))

As long as your database fields are named Level and Username you should be fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100