简体   繁体   中英

Updated Values not being Passed

This may be simple but I can't put my finger on it. I have an .aspx page that contains a list of entries created by users. There is a link associated with each record, when that link is pressed the values for that record are loaded into another page (details page) which allows the user to edit whatever fields for that record. That all works fine, simple enough.

But when the details submit button is pressed the same previous values are being resubmitted, and not the currently changed ones. So I get two identical records with different [Id] values. I watch everything in the debugger but cannot figure out why the new values are not being passed. I know its in the C# page because when I execute my stored procedure and manually type in values everything works correctly.

What am I missing here?

    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");
    }

The problem lies in your stored procedure. InsertDetailsRecords is inserting records rather than updating them. You need to pass a flag / id which will indicate that you are updating a record rather than inserting it & which record.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM