DataGrid数据更新。。。C#
点击Update之后,更新不了数据。。。用Response.Write写出来后,却是如下面的样子。void dg_Update(Object Sender,DataGridCommandEventArgs e)
{
datacon();
OleDbCommand thisCOMD=thisCN.CreateCommand();
thisCOMD.CommandText="Update students set class=@class,sex=@sex where id=@no";
thisCOMD.Parameters.Add("@class",((TextBox)e.Item.Cells[1].Controls[0]).Text);
thisCOMD.Parameters.Add("@class",((TextBox)e.Item.Cells[2].Controls[0]).Text);
thisCOMD.Parameters.Add("@no",((TextBox)e.Item.Cells[0].Controls[0]).Text);//id放在表格的第一列。
thisCOMD.Parameters["@no"].Value =dg.DataKeys [e.Item.ItemIndex];
Response.Write(""+thisCOMD.CommandText+"");//这句在浏览器中写出来的是:Update students set class=@class,sex=@sex where id=@no.
try
{
thisCOMD.ExecuteNonQuery();
}
catch
{
Response.Write("Sorry!");
}
thisCN.Close();
}