Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

can not populate textboxes with data from an access database

$
0
0
Hi,

I have a login form for people to login and get taken to another page. The page they are taken to has a label on it. The logged in user has his, her name put on the label automatically using code. The name of the label is "UserNameLoggedInLabel"

What I am trying to achieve is:

what ever name is on the label to search my database for that user and put there details in to the TextBoxes on my form.

So in my access database I have a table called "tblContacts" which has 4 fields

identifier,

UserName,

UserPassword,

UserTimer,

On my form I have 3 TextBoxes I do not want to show "identifier in the "TextBoxes"

TextBox2

TextBox3

TextBox4

On a button click I have inserted this code I am stuck with the SQL I can get it to populate my 3 TextBoxes with the data in my access database. But it only populates my TextBoxes with the data from the first row. I have tried and tried but I need a good solid example of how to achieve this can anyone help me with this line of code I need.

Thanks in advance for any help.


Code:

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = " + AppDomain.CurrentDomain.BaseDirectory + "Database1.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        If UserNameLoggedInLabel.Text = "" Then

        End If


        sql = "SELECT UserName FROM tblContacts Where UserName='" & UserNameLoggedInLabel.Text & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "database1")
        MaxRows = ds.Tables("database1").Rows.Count
        inc = -1
        TextBox2.Text = CStr(ds.Tables("database1").Rows(0).Item(1))
        TextBox3.Text = CStr(ds.Tables("database1").Rows(0).Item(2))
        TextBox4.Text = CStr(ds.Tables("database1").Rows(0).Item(3))


Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>