Click here to Skip to main content
11,720,547 members (67,892 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Access VB.NET
Hello,
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.


EDIT:

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)
            connObj.Open()
            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
            connObj.Close()
        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
tm9333605
Edited 18-Dec-12 19:49pm
v4

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 2,129
1 OriginalGriff 884
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2015
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