I'm having a problem with the error in verifying the usernames that are already existing in the record/database.


When you inputted a username that already existing it will throw an exception, and when you change the username, it still throws the exception.

You provide no code, don't say what exception is being thrown or where in the code it is being thrown and you expect what for an answer?

You really need to provide more details in order to get a good answer.

What kind of database? Version?
What is the exact error message text?

@momerath: ok i'll paste my code here.
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow

Try
If inc <> 0 And passwordTF.Text = verifyPassTF.Text Then


dsNewRow = ds.Tables("MuscleWorxGym1").NewRow()

dsNewRow.Item("FirstName") = FirstNameTF.Text.Trim
dsNewRow.Item("LastName") = LastNameTF.Text.Trim
dsNewRow.Item("Username") = usernameTF.Text.Trim
dsNewRow.Item("SecurityField") = passwordTF.Text.Trim
dsNewRow.Item("Birthdayfield") = dayBox.Text & monthBox.Text & yearBox.Text
dsNewRow.Item("WeightField") = numWeight.Text & kgbutton.Text & ", " & weightNum.Text & weightType.Text
dsNewRow.Item("HeightField") = numHeight.Text & cmbutton.Text & ", " & HeightNum.Text & HeightType.Text

ds.Tables("MuscleWorxGym1").Rows.Add(dsNewRow)
da.Update(ds, "MuscleWorxGym1")

MsgBox("Successful registration.")
Me.Close()
MainPage.Show()
Else
MsgBox("Password do not match.")
End If
Catch err As Exception
MsgBox("Username already exists.")
End Try
End Sub

@CodeWord: I'm using microsoft access .mdb

Thank you in advance. :)

One problem is that the error message "Username already exists." is shown regardless of what error you really get. For example, if you get a datatype conversion error, you show "Username already exists."

Check the value of "err" when the exception is thrown and please post the exact error message.

Thanks,

This is the exact error

"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."

Ok, after the failure, are you rejecting changes to the datatable to remove the row that had the duplicate data? If not, that row will still exist and each time you click save, it will still try to add that new row.

Something like this:

ds.Tables("MuscleWorxGym1").rejectchanges

Or, do you completely scrap the dataset and reload it after the failure to contain the latest data, without the new row?

Edited 5 Years Ago by CodeWord: n/a

Oh, hahaha, thank you for that simple code. it worked. Thank you very much.

This question has already been answered. Start a new discussion instead.