DataGrid使用中模板列出现问题
我添加模板列进行编辑、更新操作。可是当我修改完成点更新时,提示更新成功,但数据库中数据就是没有改。private void DataGrid4_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["case"];
SqlConnection sqlcon = new SqlConnection(ConnString);
//创建UPDATE命令字符串
string updatecmd = "update Case_provisional set Num_regist=@Num_regist,Year_case = @Year_case where Num_regist = @Num_regist";
SqlCommand MyCommand = new SqlCommand(updatecmd,sqlcon);
MyCommand.Connection .Open();
MyCommand.Parameters .Add(new SqlParameter("@Num_regist",SqlDbType.Char,10));
MyCommand.Parameters .Add(new SqlParameter("@Year_case",SqlDbType.Char,10));
TextBox txt1 = (TextBox)DataGrid4.Items[DataGrid4.EditItemIndex].Cells[2].FindControl("Year_case");
TextBox txt2 = (TextBox)DataGrid4.Items[DataGrid4.EditItemIndex].Cells[3].FindControl("Name_court");
//取得主键索引的值
MyCommand.Parameters["@Num_regist"].Value = DataGrid4.DataKeys[e.Item .ItemIndex];
MyCommand.Parameters["@Year_case"].Value = txt1.Text.ToString();
MyCommand.ExecuteNonQuery();
RegisterStartupScript("showSaveMessage","<script language='javascript'>alert('已更新记录!')</script>");