[英]It says I am inserting too many values in my columns when I am not?
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'.
System.Data.SqlClient.SqlException: '无效的列名 'test2test2testPassword'。 There are more columns in the INSERT statement than values specified in the VALUES clause.
INSERT 语句中的列数多于 VALUES 子句中指定的值。 The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.'
VALUES 子句中的值数必须与 INSERT 语句中指定的列数相匹配。
Could someone help?有人可以帮忙吗?
Multiple problems in your code:您的代码中存在多个问题:
insert into RegisterTable(RegUsername, RegEMail, RegPassword)
Values('test2','test2','testPassword')
The comments covered it pretty well but you are missing seperation between your values in your query on top of that you should not trust user entered text and use it directly in to queries评论很好地涵盖了它,但是您在查询中缺少值之间的分隔,此外您不应该相信用户输入的文本并将其直接用于查询
you should used paramatized commands like this你应该使用像这样的参数化命令
var checkCount =
new SqlCommand("insert into [TableName] (id, othercolumn) VALUES(@id, @otherColumn)",
conn);
checkCount.Parameters.AddWithValue("@id", id);
checkCount.Parameters.AddWithValue("@otherColumn", otherColumn);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.