简体   繁体   English

它说我在我的列中插入了太多的值,而我不是?

[英]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:您的代码中存在多个问题:

  1. You should use parameters in your queries: https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.parameters?view=dotnet-plat-ext-5.0您应该在查询中使用参数: https : //docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.parameters?view=dotnet-plat-ext-5.0
  2. The values should be comma separated: Best way to store password in database值应以逗号分隔: Best way to store password in database
insert into RegisterTable(RegUsername, RegEMail, RegPassword)
                   Values('test2','test2','testPassword')
  1. Never store unhashed passwords in your database永远不要在您的数据库中存储未散列的密码

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.

相关问题 编译器说我没有实现我的接口,但我是吗? - Compiler says I am not implementing my interface, but I am? 为什么我在发送表单时没有得到 wright 值? - Why am I not getting the wright values when sending my form? IoC,SRP和合成-我是否创建了太多接口? - IoC, SRP and composition - am I creating too many interfaces? 我在使用C#插入数据库时​​遇到问题 - I am having trouble inserting into my database with c# 使用流利的nhibernate时是否会错误地进行很多操作? - Am I doing many to many incorrectly when using fluent nhibernate? 当我将新行插入数据库表时,SignalR 未触发 - SignalR not fired when I am inserting a new row into database table 当我在多对多情况下插入时,“实体对象不能被 IEntityChangeTracker 的多个实例引用”? - "An entity object cannot be referenced by multiple instances of IEntityChangeTracker" while I am inserting on a many-to-many situation? 当我尝试在if()中使用变量时,它表示我正在使用未分配的变量 - When I try to use a variable in an if() it says that I am using an unassigned variable 插入SQL时出现错误 - I am getting error while inserting to SQL 为什么我会收到一条错误消息,说明我的下拉列表没有视图数据? - Why am I getting an error that says there's no view data for my dropdownlist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM