博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决异常“SqlParameterCollection 只接受非空的 SqlParameter 类型对象。”
阅读量:7072 次
发布时间:2019-06-28

本文共 1374 字,大约阅读时间需要 4 分钟。

[c-sharp] 
  1. public void DataList_UpdateCommand(Object sender, DataListCommandEventArgs e)  
  2.  {  
  3.      string strName = ((Label)e.Item.FindControl("lblName")).Text;  
  4.      int intChinese = Int32.Parse(((TextBox)e.Item.FindControl("tbChinese")).Text);  
  5.      int intMath = Int32.Parse(((TextBox)e.Item.FindControl("tbMath")).Text);  
  6.      int intEnglish = Int32.Parse(((TextBox)e.Item.FindControl("tbEnglish")).Text);  
  7.      //更新数据库中的数据  
  8.      string strUpdate = "Update Score Set Chinese=@intChinese,Math=@intMath,English=@intEnglish Where Name=@strName";  
  9.      SqlParameter[] paras = new SqlParameter[10];  
  10.      paras[0] = new SqlParameter("@strName", SqlDbType.VarChar);  
  11.      paras[0].Value = strName;  
  12.   
  13.      paras[1] = new SqlParameter("@intChinese", SqlDbType.Int);  
  14.      paras[1].Value = intChinese;  
  15.   
  16.      paras[2] = new SqlParameter("@intMath", SqlDbType.Int);  
  17.      paras[2].Value = intMath;  
  18.   
  19.      paras[3] = new SqlParameter("@intEnglish", SqlDbType.Int);  
  20.      paras[3].Value = intEnglish;  
  21.   
  22.      bool temp = NewsDB.Getcmd(strUpdate, paras);  
  23.      score.EditItemIndex = -1;  
  24.      ListBind();  
  25.  }  

一直报错“SqlParameterCollection 只接受非空的 SqlParameter 类型对象”。

后来将

[c-sharp] 
  1. SqlParameter[] paras = new SqlParameter[10];  

改成

[c-sharp] 
  1. SqlParameter[] paras = new SqlParameter[4];  

以后解决错误。

[c-sharp] 
  1. SqlParameter[] paras = new SqlParameter[10];  

是我从别的地方拷贝过来的,而不是自己写的。现在越来越发现拷贝代码虽然快,但是往往存在许多连自己都不易发现的错误。

本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2010/03/18/2297154.html,如需转载请自行联系原作者

你可能感兴趣的文章
angularjs基本执行流程
查看>>
线段树 + 区间更新: HDU 4893 Wow! Such Sequence!
查看>>
再探vim经常使用命令
查看>>
[BZOJ 1066][SCOI2007]蜥蜴
查看>>
platform_device与platform_driver
查看>>
sql中update,alter,modify,delete,drop的区别和使用(整理)(转)
查看>>
Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
查看>>
MySql性能优化相关
查看>>
Android学习笔记——Intents 和 Intent Filters(二)
查看>>
收藏的Android很好用的组件或者框架。
查看>>
SQL Server 数据库文件 4 点注意
查看>>
赛马题(转)
查看>>
网页的背景图片代码
查看>>
SURF算法与源码分析、下
查看>>
高速排序算法
查看>>
数学图形之伞形
查看>>
vs2008打包公布程序
查看>>
浅谈WebService的版本兼容性设计
查看>>
随便弄个名字 以后改
查看>>
opennebula auth module ldap
查看>>