[英]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.