Hi all,
I'm trying to make a form wich can make new users in a Access database. However, usernames can't be duplicate, but I can't seem to get the code to work so users can't enter 2 of the same entries. Can anyone help?
Private Sub btnAanmaken_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAanmaken.Click
Dim strNaam As String
Dim blnZoeken As Boolean
strNaam = txtNaam.Text
GebruikersDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Dim intcount As Integer = 0
For Each Row As DataGridViewRow In GebruikersDataGridView.Rows
If GebruikersDataGridView.Rows(intcount).Cells(1).Value.ToString = strNaam Then
GebruikersDataGridView.Rows(intcount).Selected = True
blnZoeken = True
Exit For
End If
intcount += 1
Next Row
If blnZoeken = True Then
MessageBox.Show("Naam bestaat al", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If txtWachtwoord.Text = txtWachtwoordHerhaal.Text Then
MessageBox.Show(strNaam & " is met succes aangemaakt!", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Validate()
Me.GebruikersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EasybyteDataSet)
Me.Close()
Hoofdmenu.Show()
Else
MessageBox.Show("Wachtwoord is fout", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
End Sub