I’m trying to check username and password by using a For Each Statement. If it validates then messagebox saying welcome appears, if it doesn’t a message box saying “incorrect” will keep popping up over and over until it’s done looping through the table. How can i correct this and just make it display one time. Also when it does validate a new window will show up with users First and Last name in a textbox, How can I edit users info and then save to db. Thanks for any help.
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim data As New datalinq1DataContext
For Each row In data.Users
If Not row.username = TextBox1.Text And Not row.password = TextBox2.Text Then
Messagebox.Show("Incorrect")
Else
MessageBox.Show("Welcome " + row.fname + " " + row.lname)
Dim window As New Window1
window.TextBox1.Text = row.fname
window.TextBox2.Text = row.lname
window.TextBox3.Text = row.username
window.Show()
Exit For
End If
Next
End Sub
You could add an EXIT FOR after the msg box, but why are there multiple records being checked in the user table. You should filter the user table to just the username entered.