By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Display Data from Local VB Database in a label after clicking a buttong

P: 1
I have created a simple log on screen that checks the local database if the username and password exist and to add them to the database if it doesn't exist.

On the Login window I have a Label that I would like to equal the user who has logged on.


Here is my code.....



Expand|Select|Wrap|Line Numbers
  1. Public Class loginWindow
  2.  
  3.     Private Users As New UsersDataSetTableAdapters.CredentialsTableAdapter
  4.     Private DataSet As New UsersDataSet
  5.  
  6.     Private Sub Register(ByVal Username As String, ByVal Password As String)
  7.         Dim Row As UsersDataSet.CredentialsRow = DataSet.Credentials.FindByUsername(Username)
  8.         If Row Is Nothing Then
  9.             DataSet.Credentials.AddCredentialsRow(Username, Password)
  10.             Users.Update(DataSet)
  11.             MessageBox.Show("Account Created")
  12.         Else
  13.             MessageBox.Show("Username not available please choose another!")
  14.         End If
  15.  
  16.  
  17.     End Sub
  18.     Private Sub Login(ByVal Username As String, ByVal Password As String)
  19.         Dim Row As UsersDataSet.CredentialsRow = DataSet.Credentials.FindByUsername(Username)
  20.         If Not Row Is Nothing AndAlso Row.Password = Password Then
  21.             MessageBox.Show("Correct Credentials Logging in!")
  22.         Else
  23.             MessageBox.Show("Invalid Credentials")
  24.         End If
  25.     End Sub
  26.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  27.  
  28.         Users.Fill(DataSet.Credentials())
  29.     End Sub
  30.  
  31.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles LoginButton.Click
  32.  
  33.         Label1.Text = 
  34.  
  35.  
  36.         Call Login(UsernameTextBox.Text, LoginTextBox.Text)
  37.  
  38.     End Sub
  39.  
  40.     Private Sub RegistrationButton_Click(sender As System.Object, e As System.EventArgs) Handles RegistrationButton.Click
  41.         Call Register(UsernameTextBox.Text, LoginTextBox.Text)
  42.     End Sub
  43.  
  44.     Private Sub LoginTextBox_Click(sender As Object, e As System.EventArgs) Handles LoginTextBox.Click
  45.         LoginTextBox.Text = ""
  46.     End Sub
  47.  
  48.     Private Sub UsernameTextBox_Click(sender As Object, e As System.EventArgs) Handles UsernameTextBox.Click
  49.         UsernameTextBox.Text = ""
  50.     End Sub
  51.  
  52. End Class
Jun 20 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.