Click here to Skip to main content
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
tm9333631
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 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 vikinghunter 168
4 OriginalGriff 166
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2014
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