I am creating a login menu and I put in the details:
Username:test2 Email:Test2 Password: testPassword Confirm Password: testPassword
The confirm password must be the same as password for it to go into the database so it would be one value
then i get the error:
System.Data.SqlClient.SqlException: ‘Invalid column name ‘test2test2testPassword’. There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.’
Could someone help?
Advertisement
Answer
Multiple problems in your code:
- You should use parameters in your queries: https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.parameters?view=dotnet-plat-ext-5.0
- The values should be comma separated:
insert into RegisterTable(RegUsername, RegEMail, RegPassword) Values('test2','test2','testPassword')
- Never store unhashed passwords in your database. See Best way to store password in database