Skip to content
Advertisement

It says I am inserting too many values in my columns when I am not? [closed]

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

enter image description here

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:

  1. 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
  2. The values should be comma separated:
insert into RegisterTable(RegUsername, RegEMail, RegPassword)
                   Values('test2','test2','testPassword')
  1. Never store unhashed passwords in your database. See Best way to store password in database
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement