我的插入和删除功能工作正常,但编辑功能出现问题。编辑功能仅适用于该行的第一行,但如果我尝试编辑第二行或第三行,则会收到此错误:“必须声明标量变量“@Post_ID”这是我的代码:
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
int id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
TextBox date = (TextBox)row.FindControl("date");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update t_your_table " +
"set " +
"date = @date, " +
" time = @time where id = @ID "
cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = id;
cmd.Parameters.Add("@date", SqlDbType.VarChar).Value = date.Text;