1

Below is the code to update gridview. In gridview, i m using dropdownlists, datepicker and text boxes in the update grid. I m getting all the value correct.. Main issue is i m not able to update Case_Status and Case_Type in the database. if i m updating then both values updated as NULL in database. I checked the values of V1 and V2 by using breakpoints in Visual Studio. Both values are desired result. but updating NULL...

On " GridView1.EditIndex = -1;" I am getting value 4 while checking through breakpoints..

    con.Open();
    SqlCommand cmd = new SqlCommand("UPDATE intakesheet SET case_number = @case_number, case_name = @case_name, Case_Type = @Case_Type, Case_Status = @Case_Status, assigned_date = @assigned_date, assigned_to = @assigned_to, date_withdrawn= @date_withdrawn, date_delivered= @date_delivered, qc_by = @qc_by,  qc_date= @qc_date, additional_notes = @additional_notes WHERE (case_number = @case_number)", con);
    cmd.Parameters.Add("@case_number", SqlDbType.NVarChar).Value = case_number;
    cmd.Parameters.Add("@case_name", SqlDbType.NVarChar).Value = case_name;
    cmd.Parameters.AddWithValue("@Case_Type", v1);
    cmd.Parameters.AddWithValue("@Case_Status", v2);
    cmd.Parameters.Add("@assigned_date", SqlDbType.NVarChar).Value = assigned_date;
    cmd.Parameters.AddWithValue("@assigned_to", assigned_to);
    cmd.Parameters.AddWithValue("@date_withdrawn", date_withdrawn);
    cmd.Parameters.AddWithValue("@date_delivered", date_delivered);
    cmd.Parameters.AddWithValue("@qc_by", qc_by);
    cmd.Parameters.AddWithValue("@qc_date", qc_date);
    cmd.Parameters.Add("@additional_notes", SqlDbType.NVarChar).Value = additional_notes;

    cmd.ExecuteNonQuery();
    GridView1.EditIndex = -1;
    con.Close();

}
1
  • What's the DbType of Case_Type and Case_Status? Commented Aug 3, 2013 at 4:19

2 Answers 2

1
cmd.Parameters.AddWithValue("@Case_Type", Integer.Parse(v1));
cmd.Parameters.AddWithValue("@Case_Status", Integer.Parse(v2));

Try this code!

Sign up to request clarification or add additional context in comments.

1 Comment

you should use "int.Parse(V1)"
0

convert your value into string.....

cmd.Parameters.AddWithValue("@Case_Type", v1.ToString());
cmd.Parameters.AddWithValue("@Case_Status", v2.ToString());

1 Comment

both type must be same.... your datatype in database and datatype while inserting data must be same...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.