I’m trying to register a user, with the following query:
"INSERT INTO Users (Username, Password, FirstName, Surname, Age, HouseNumber,
StreetName, Town, County, Postcode, TelephoneNumber,
isBanned, isAdmin)
VALUES ('" + textboxUsername.Text + "','" + textboxPassword.Text + "','" +
textboxFirstName.Text + "','" + textboxSurname.Text + "','" + textboxAge.Text + "','" + textboxHouseNumber.Text +
"','" + textboxStreetName.Text + "','" +
textboxTown.Text + "','" + textboxCounty.Text + "','" +
textboxPostcode.Text + "','" + textboxTelephoneNumber.Text +
"', 'false', 'false')", con);
The database is set up as you would expect, with only the above values and UserID, which should be an auto increment value using Identity Specification. However, I get the following error:
Cannot insert the value NULL into column 'UserID', table 'myFilePath'; column does not allow nulls. INSERT fails.
Why is this? I can’t tell it to insert anything for the UserID as the database needs to handle that, currently the UserID is the primary key and as such can’t be not null. What am I doing wrong? This used to work a few months ago
You can also mention
idasNULLin query. It will get filled usingauto-increment:Also check for the data type of field
UserIDIt should be something like this: