EDN Admin
Well-known member
Hi there,
I wonder if you could help me. I use an Access Database, and the application requires a user to log in with their allocated username and password. How do I display certain data from the database for that specific user, such as their name, etc. on a form?
Heres the current Log in code I use.
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=xxxxxxxx.mdb")
Dim cmd As OleDbCommand = New OleDbCommand( _
"SELECT * FROM StudentInfo WHERE StudentNumber = " & _
UsernameTextBox.Text & " AND [IDNumber] = " & PasswordTextBox.Text & " ", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If the record can be queried, it means passing verification, then open another form.
If (sdr.Read() = True) Then
MessageBox.Show("User Authenticated!")
Dim mainForm As New MainMenu
mainForm.Show()
Me.Close()
Else
MessageBox.Show("Invalid username or password!")
End If
End Sub[/code]
<br/>
View the full article
I wonder if you could help me. I use an Access Database, and the application requires a user to log in with their allocated username and password. How do I display certain data from the database for that specific user, such as their name, etc. on a form?
Heres the current Log in code I use.
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=xxxxxxxx.mdb")
Dim cmd As OleDbCommand = New OleDbCommand( _
"SELECT * FROM StudentInfo WHERE StudentNumber = " & _
UsernameTextBox.Text & " AND [IDNumber] = " & PasswordTextBox.Text & " ", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If the record can be queried, it means passing verification, then open another form.
If (sdr.Read() = True) Then
MessageBox.Show("User Authenticated!")
Dim mainForm As New MainMenu
mainForm.Show()
Me.Close()
Else
MessageBox.Show("Invalid username or password!")
End If
End Sub[/code]
<br/>
View the full article