[英]Updated Values not being Passed
这可能很简单,但是我不能动弹。 我有一个.aspx页面,其中包含用户创建的条目列表。 每个记录都有一个链接,当按下该链接时,该记录的值将被加载到另一个页面(详细信息页面)中,该页面允许用户编辑该记录的任何字段。 一切正常,足够简单。
但是,当按下详细信息提交按钮时,相同的先前值将被重新提交,而不是当前更改的值。 因此,我得到了两个具有相同[Id]值的相同记录。 我在调试器中查看了所有内容,但无法弄清楚为什么未传递新值。 我在C#页面中知道它,因为当我执行存储过程并手动键入值时,一切都可以正常工作。
我在这里想念什么?
protected void SubmitDetails_Click(object sender, EventArgs e)
{
//Connection to the sql db and the stored procedure.
SqlConnection sqlConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("dbo.InsertDetailsRecords", sqlConn);
sqlConn.Open();
command.CommandType = CommandType.StoredProcedure;
//Parameters being passed to the stored procedure to go into the table.
command.Parameters.Add(new SqlParameter("@Date", (Datetxt.Text)));
command.Parameters.Add(new SqlParameter("@Title", (TitleBox.Text)));
command.Parameters.Add(new SqlParameter("@FirstName", (FirstNameBox.Text)));
command.Parameters.Add(new SqlParameter("@LastName", (LastNameBox.Text)));
command.Parameters.Add(new SqlParameter("@Comments", (CommentsBox.Text)));
command.Parameters.Add(new SqlParameter("@Categories", DropDownListCategory.SelectedValue));
command.Parameters.Add(new SqlParameter("@Centers", DropDownListCenters.SelectedValue));
command.Parameters.Add(new SqlParameter("@Status", DownListStatus.SelectedValue));
command.ExecuteNonQuery();
sqlConn.Close();
//Redirecting to the list page once the submit button is pressed.
Response.Redirect("List.aspx");
}
问题出在您的存储过程中。 InsertDetailsRecords正在插入记录,而不是对其进行更新。 您需要传递一个标志/ ID,该标志/ ID将指示您正在更新记录,而不是插入记录和记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.