System.InvalidCastException: 指定的转换无效。 at WebApplication2.WebForm1.DataGrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\documents and settings\administrator\my documents\visual studio projects\webapplication2\webform1.aspx.cs:line 176private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{//更新
try
{
string a=(string)this.DataGrid1.DataKeys[e.Item.ItemIndex];//取出当前行的关键字的值
sqlUpdateCommand1=this.sqlConnection1.CreateCommand();
sqlUpdateCommand1.CommandText="update tab set a=@a,b=@b where a=a";
sqlUpdateCommand1.Parameters.Add("@a",SqlDbType.Char,10,"a");
sqlUpdateCommand1.Parameters.Add("@b",SqlDbType.Char,10,"b");
sqlUpdateCommand1.Parameters["@a"].Value=DataGrid1.DataKeys[e.Item.ItemIndex];
sqlUpdateCommand1.Parameters["@b"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
this.sqlUpdateCommand1.ExecuteNonQuery();
this.DataGrid1.EditItemIndex=-1;
this.DataGrid1.DataBind();
}
catch(System.Exception er)
{
Response.Write(er.ToString());
}
}请赐教 谢谢
{//更新
try
{
string a=(string)this.DataGrid1.DataKeys[e.Item.ItemIndex];//取出当前行的关键字的值
sqlUpdateCommand1=this.sqlConnection1.CreateCommand();
sqlUpdateCommand1.CommandText="update tab set a=@a,b=@b where a=a";
sqlUpdateCommand1.Parameters.Add("@a",SqlDbType.Char,10,"a");
sqlUpdateCommand1.Parameters.Add("@b",SqlDbType.Char,10,"b");
sqlUpdateCommand1.Parameters["@a"].Value=DataGrid1.DataKeys[e.Item.ItemIndex];
sqlUpdateCommand1.Parameters["@b"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
this.sqlUpdateCommand1.ExecuteNonQuery();
this.DataGrid1.EditItemIndex=-1;
this.DataGrid1.DataBind();
}
catch(System.Exception er)
{
Response.Write(er.ToString());
}
}请赐教 谢谢
解决方案 »
- localhost怎么也连接不上,127.0.0.1就行,怎么办?
- checkBox 树 横排排列
- 倒计时
- 看下这个表达正则怎么改
- 字符串过长问题??
- ...此面正在访问其它域的数据,你允许这样做吗?如何出掉这个窗口
- webservice session 丢失问题!!!!!!!!!!!!!!
- 50分请教大家 一个datagrid模版列 问题!!!!!!!!!!!
- 请问datagrid.items[4].cells[0].text?
- 关于Session奇怪的问题!!!(昨天还正常,睡了一觉,就开始出错了)Help me!
- ASP.NET中文本框取到系统当前时间后,怎么做出走动效果?用脚本怎么实现?
- 急求一个超难存储过程,高手急救,在线等
估计sqlUpdateCommand1.Parameters["@a"].Value=DataGrid1.DataKeys[e.Item.ItemIndex];
改成sqlUpdateCommand1.Parameters["@a"].Value=DataGrid1.DataKeys[e.Item.ItemIndex].ToString();试试