但未在用户代码中处理

但未在用户代码中处理

本文介绍了system.data.dll中发生了'system.data.sqlclient.sqlexception'类型的异常,但未在用户代码中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过Session从Dynamic.aspx将4个数据从1页传递到另一个页面到 AddPage.aspx ,如下所述:

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();





现在 update_Button 点击我要更新数据,如下所述:





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.

推荐答案

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();



你已经注释掉参数@ID......所以它正在做我期望它做的......

要么返回teh参数,要么修改SP不需要它。


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.


这篇关于system.data.dll中发生了'system.data.sqlclient.sqlexception'类型的异常,但未在用户代码中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 02:48