简体   繁体   English

SqlParameterCollection仅接受非空的SqlParameter类型对象。 参数名称:值

[英]The SqlParameterCollection only accepts non-null SqlParameter type objects. Parameter name: value

我有一个将数据保存到数据库的注册页面,唯一的问题是当我单击注册按钮时,我收到一个错误消息,该消息不是很确定如何解决,请参阅下文。

Your declaring param[] to have 6 elements, but you're only using 5. The last one is null so you're getting the error on the last iteration of your for loop where you add the elements to the SqlParameterCollection . 您声明的param[]具有6个元素,但您仅使用5个元素。最后一个为null因此在将元素添加到SqlParameterCollection for循环的最后一次迭代中遇到错误。

It would be much cleaner/easier to do the following rather than declaring an array, filling the array, and then trying to copy the array: 与声明一个数组,填充该数组然后尝试复制该数组相比,执行以下操作会更清洁/更轻松:

cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Gender", gender);
cmd.Parameters.AddWithValue("@Age", age);
cmd.Parameters.AddWithValue("@Address", address);
cmd.Parameters.AddWithValue("@Email", email); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.InvalidCastException:“SqlParameterCollection 只接受非空 SqlParameter 类型对象,不接受 SqlParameter 对象。” - System.InvalidCastException: 'The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.' SqlParameterCollection 只接受非空的 SqlParameter 类型对象,而不接受 Microsoft.Data.SqlClient 中的 SqlParameter 对象 - The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects in Microsoft.Data.SqlClient SqlParameterCollection 只接受非空的 Parameter 类型对象 - The SqlParameterCollection only accepts non-null Parameter type objects SqlParameterCollection只接受非null的SqlParameter类型对象,而不接受DBNull对象 - SqlParameterCollection only accepts non-null SqlParameter type objects, not DBNull objects sqlparametercollection 只接受非空的 sqlparameter 类型对象,而不是 byte[] 对象 - the sqlparametercollection only accepts non-null sqlparameter type objects not byte[] objects 错误:SqlParameterCollection仅接受非null的SqlParameter类型对象,而不接受String对象 - Error : The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects SqlParameterCollection仅接受非null SqlParameter类型的对象,不接受DBNull对象 - The SqlParameterCollection only accepts non-null SqlParameter type objects, not DBNull objects “SqlParameterCollection 只接受非空的 SqlParameter 类型对象,不接受 String 对象” - “SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects” SqlParameterCollection仅接受非空的SqlParamter类型对象,而不接受String对象 - The SqlParameterCollection only accepts non-null SqlParamter type objects, not String objects Database.ExecuteSqlRaw - 只接受非空的 SqlParameter 类型对象 - Database.ExecuteSqlRaw - only accepts non-null SqlParameter type objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM