Click here to Skip to main content
14,736,856 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've passed 4 data from 1 page to another through Session from Dynamic.aspx to AddPage.aspx, as mentioned bellow:
Session["currentID"] = dt.Rows[0]["ID"].ToString();
Session["currentPgNm"] = tempPageName.ToString();
Session["currentTitle"] = dt.Rows[0]["Title"].ToString();
Session["currentContent"] = dt.Rows[0]["Content"].ToString();

Response.Redirect("~/AddPage.aspx");


Then I hold all these data like this as mentioned below:
strID = Session["currentID"].ToString();
txt_PgNm.Text = Session["currentPgNm"].ToString();
txt_title.Text = Session["currentTitle"].ToString();
txt_DesignContent.Text = Session["currentContent"].ToString();


Now on update_Button click I want to update data, mentioned below:

protected void btn_Update_Click(object sender, EventArgs e)
{
     con.Open();
     SqlCommand cmd = new SqlCommand("uspUpdate", con);
     //cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(strID));
     cmd.Parameters.AddWithValue("@PageName", txt_PgNm.Text);
     cmd.Parameters.AddWithValue("@Title", txt_title.Text);
     cmd.Parameters.AddWithValue("@Content", txt_DesignContent.Text);
     int x = cmd.ExecuteNonQuery();   //This line shows Error
     con.Close();
     if (x >= 1)
     {
          lblConfirm.Visible = true;
          lblConfirm.Text = "Successfully updated";
     }
}


ERROR: An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code.

Additional information: Procedure or function 'uspUpdate' expects parameter '@ID', which was not supplied.


What I have tried:

Yes I've tried it no. of times and even try to resolve the problem by taking help from Developer's blogs and post, but could not able to.
Posted
Updated 10-Feb-16 0:16am
v2
Comments
Philippe Mori 12-Feb-16 22:32pm
   
In that case, there error message is very clear and need no extra explanation.

1 solution

Well... the error does explain exactly what is wrong:
Procedure or function 'uspUpdate' expects parameter '@ID', which was not supplied.
And looking at your code:
SqlCommand cmd = new SqlCommand("uspUpdate", con);
//cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(strID));
cmd.Parameters.AddWithValue("@PageName", txt_PgNm.Text);
cmd.Parameters.AddWithValue("@Title", txt_title.Text);
cmd.Parameters.AddWithValue("@Content", txt_DesignContent.Text);
int x = cmd.ExecuteNonQuery();

You have commented out the parameter "@ID"...so it's doing exactly what I would expect it to do...
Either put teh parameter back, or modify the SP to not require it.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900