EDN Admin
Well-known member
Hi all
I am wanting to display specific data from my access database. My access database has 3 rows
UserName
UserPassword
UserTimer
I can write information to my database no problems, but what I would really like is to be able to display a specific row in 3 TextBoxs I have on my windows form.
So when someone clicks on a button lets say "Button3" it ill display the username password and timer (which is a number) in the 3 textboxs of whom ever it was that logged in
Now you will see in my code below I can get it to display the information of the person who logged in. But this information comes from the login form not the database. I can also get it to display the first row of information in the database. But once again I still can not get he information from the database of whom ever logs in.
Can anyone help out by giving me an example. I have included what I believe is the relevant code.Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:UsersNigeDocumentsVisual Studio 2012ProjectsMS_Access_SimplePasswordbinDebugDatabase1.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "database1")
MsgBox("Database is now open")
con.Close()
MaxRows = ds.Tables("database1").Rows.Count
inc = -1
MsgBox("Database is now Closed")
txtFirstName.Text = CStr(ds.Tables("database1").Rows(0).Item(1))
txtSurname.Text = CStr(ds.Tables("database1").Rows(0).Item(2))
txtTimer.Text = CStr(ds.Tables("database1").Rows(0).Item(3))
The code below just checks what user logged in and displays there name in a label.
I was thinking maybe I could somehow incorporate this code. So that the logged in user has there name displayed in the label (like it is now) and the database gets searched for what ever name appears in the label.
LoginForm.txtUserName.Text = LoginForm.txtUserName.Text
If LoginForm.txtUserName.Text <> "" Then
End If
lblName.Text = LoginForm.txtUserName.Text
con.Close()
End SubImports System.Data.OleDb
Public Class frmMainform
Private LoginAttempts As Integer
Dim ds As New DataSet
Dim dbProvider As String
Dim dbSource As String
Dim inc As Integer
Dim con As New OleDb.OleDbConnection
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim WelcomeName As String
Dim MaxRows As Integer
Dim UserTimer As Integer
Thanks
View the full article
I am wanting to display specific data from my access database. My access database has 3 rows
UserName
UserPassword
UserTimer
I can write information to my database no problems, but what I would really like is to be able to display a specific row in 3 TextBoxs I have on my windows form.
So when someone clicks on a button lets say "Button3" it ill display the username password and timer (which is a number) in the 3 textboxs of whom ever it was that logged in
Now you will see in my code below I can get it to display the information of the person who logged in. But this information comes from the login form not the database. I can also get it to display the first row of information in the database. But once again I still can not get he information from the database of whom ever logs in.
Can anyone help out by giving me an example. I have included what I believe is the relevant code.Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:UsersNigeDocumentsVisual Studio 2012ProjectsMS_Access_SimplePasswordbinDebugDatabase1.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "database1")
MsgBox("Database is now open")
con.Close()
MaxRows = ds.Tables("database1").Rows.Count
inc = -1
MsgBox("Database is now Closed")
txtFirstName.Text = CStr(ds.Tables("database1").Rows(0).Item(1))
txtSurname.Text = CStr(ds.Tables("database1").Rows(0).Item(2))
txtTimer.Text = CStr(ds.Tables("database1").Rows(0).Item(3))
The code below just checks what user logged in and displays there name in a label.
I was thinking maybe I could somehow incorporate this code. So that the logged in user has there name displayed in the label (like it is now) and the database gets searched for what ever name appears in the label.
LoginForm.txtUserName.Text = LoginForm.txtUserName.Text
If LoginForm.txtUserName.Text <> "" Then
End If
lblName.Text = LoginForm.txtUserName.Text
con.Close()
End SubImports System.Data.OleDb
Public Class frmMainform
Private LoginAttempts As Integer
Dim ds As New DataSet
Dim dbProvider As String
Dim dbSource As String
Dim inc As Integer
Dim con As New OleDb.OleDbConnection
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim WelcomeName As String
Dim MaxRows As Integer
Dim UserTimer As Integer
Thanks
View the full article