I have a database containing various users, and I need to change the value of their gender.
When they register the only data added to the table Users
is the Username and the Password leaving the gender blank.
I have a button to add other information just like the gender, I tried to use the update query, the program runs with no errors but when I open the database to see the result nothing is added/changed.
Table example:
id | Username | Password | Gender |
---|---|---|---|
1 | usrExmpl | pwdExmpl |
What I'm trying to do is to add a value for the gender, either "Male" or "Female" to the respective user, this is what I tried:
Dim gender As String = txtGender.txt
Dim queryGender As String = "UPDATE Users SET Gender=@Gender WHERE Username=@Username"
Using cmdGender= New OleDbCommand(queryGender, conn)
cmdGender.Parameters.Add("Username", OleDbType.VarChar).Value = My.Settings.currentUser
cmdGender.Parameters.Add("Gender", OleDbType.VarChar).Value = gender
If conn.State = ConnectionState.Closed Then conn.Open()
cmdGender.ExecuteNonQuery()
cmdGender.Dispose()
End Using
This gives me no errors and the table doesn't get updated either.
NB: My.Settings.currentUser
is a string that contains the username of the current logged-in user and is correct and functioning like it should.
Edit: Thanks to @GSerg i fixed it, the problem was that i wasn't adding the parameters in the same order as the one in the query, i swapped them following the correct order.