C#: 过程或函数""需要""参数,但未提供该参数

在平时的C#项目开发中,当调用某个存储过程或函数的时候,我们可能经常会遇到这样的问题,

“过程或函数XXX需要XXX参数,但未提供该参数”,  这到底是怎么回事呢?是什么问题引起的?

出现这个错误一般会由以下几种情况引起:

1.  程序中传入参数与已定义的存储过程或函数的参数个数或名称不符;

2.  没有对传入的数据作空值的处理,如下,我们需要对可以为空的值作这样的处理,一旦其为空,就设置为DBNull.value.

foreach(SqlParameter p in parms)
{
  if(p.value == null)
  {
  p.value=DBNull.value;
  }
}

3. 传入了参数,却没有真正通过sqlCommand去操作。

所以当遇到这样的问题,首先需要做的就是检查一下写的代码是否属于这几种情况,如果是就做相应处理,或者考虑定义的变量是否被初始化。 

阅读更多
换一批

过程需要参数但未提供参数

04-03

我用sqlhelper.cs类rn /// rn /// 执行一条返回结果集的SqlCommand命令,通过专用的连接字符串。rn /// 使用参数数组提供参数rn /// rn /// rn /// 使用示例: rn /// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));rn /// rn /// 一个有效的数据库连接字符串rn /// SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)rn /// 存储过程的名字或者 T-SQL 语句rn /// 以数组形式提供SqlCommand命令中用到的参数列表rn /// 返回一个包含结果的SqlDataReaderrn public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)rn rn SqlCommand cmd = new SqlCommand();rn SqlConnection conn = new SqlConnection(connectionString);rnrn // 在这里使用try/catch处理是因为如果方法出现异常,则SqlDataReader就不存在,rn //CommandBehavior.CloseConnection的语句就不会执行,触发的异常由catch捕获。rn //关闭数据库连接,并通过throw再次引发捕捉到的异常。rn tryrn rnrn PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);rn rn [color=#FF0000][color=#FF0000][color=#FF0000] SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior .CloseConnection );//rdr为空[/color][/color][/color] rn cmd.Parameters.Clear();rn return rdr;rn rn catchrn rn conn.Close();rn throw;rn rn finallyrn rn if (conn.State != ConnectionState.Closed) rn rn conn.Close();rn rn rn rn private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)rn rnrn //判断数据库连接状态rn if (conn.State != ConnectionState.Open)rn rn conn.Open();rn rnrn cmd.Connection = conn;rn cmd.CommandText = cmdText;rnrn //判断是否需要事物处理rn if (trans != null)rn cmd.Transaction = trans;rnrn cmd.CommandType = cmdType;rnrn if (cmdParms != null)rn rn foreach (SqlParameter parm in cmdParms)rn cmd.Parameters.Add(parm);rn rn rn存储过程:rnALTER PROCEDURE Pr_GetUserLoginrn(rn @UserName varchar(200),rn @Password varchar(255)rn)rnASrnrnSELECTrn UserID rnrnFROMrn [User]rn rnWHERErn UserName = @UserName AND Password = @Passwordrnrnrnrn“/graduateproject”应用程序中的服务器错误。rn--------------------------------------------------------------------------------rnrn过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.SqlClient.SqlException: 过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。rnrn源错误: rnrnrn行 129: rn行 130: conn.Close();rn行 131: throw;rn行 132: rn行 133: finallyrn rnrn源文件: d:\graduateproject\App_Code\SqlHelper.cs 行: 131 rnrn堆栈跟踪: rnrnrn[SqlException (0x80131904): 过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95rn System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244rn System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52rn System.Data.SqlClient.SqlDataReader.get_MetaData() +130rn System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371rn System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +162rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +87rn SqlHelper.ExecuteReader(String connectionString, CommandType cmdType, String cmdText, SqlParameter[] commandParameters) in d:\graduateproject\App_Code\SqlHelper.cs:131rn ResourceMananer.User.GetUserLogin(String sUserName, String sPassword) in d:\graduateproject\App_Code\User.cs:29rn _Default.logbt_Click(Object sender, EventArgs e) in d:\graduateproject\Default.aspx.cs:49rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838rnrn 帮忙看看,谢谢啦!rn

过程需要参数但未提供参数

04-07

做了个简单的三层,向数据库中添加东西,用得存储过程,因为不太熟悉,所以一直出现问题,但是我却不知道究竟什么地方出现了问题!请教大家!rnBLL层:rn public News SelectById(string id)rn rn return ndao.SelectById(id);rn rn public DataTable SelectByNewsId(string newsId)rn rn return cdao.SelectByNewsId(newsId);rn rnDAL层:rnpublic News SelectById(string id)rn rn //TODO:根据类别ID取出该条新闻主题内容rn News n = new News();rn DataTable dt = new DataTable();rn string cmdText = "news_selectById";//存储过程rn SqlParameter[] paras = new SqlParameter[] rn new SqlParameter("@id", id)rn ;rn dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);rn n.Id = id;rn n.Title = dt.Rows[0]["title"].ToString();rn n.Content = dt.Rows[0]["content"].ToString();rn n.CreateTime = dt.Rows[0]["createTime"].ToString();rn n.CaId = dt.Rows[0]["caId"].ToString();rn return n;rn rnWEB层:rnprotected void Page_Load(object sender, EventArgs e)rn rn if (!Page.IsPostBack)rn rn string newsid =Request.QueryString["newsid"];rn NewsManager nm = new NewsManager();rn News news = nm.SelectById(newsid);rn //设置新闻主题rn lblTitle.Text = news.Title;rn lblContent.Text = news.Content;rn lblCreateTime.Text = news.CreateTime;rn //绑定新闻评论rn repComment.DataSource = new CommentManager().SelectByNewsId(newsid);rn repComment.DataBind();rn rn rn在运行过程中老提示说:过程 'news_selectById' 需要参数 '@id',但未提供该参数。 请大家帮忙给看看怎么回事。rn

需要参数 '@adminAccount',但未提供参数

05-08

“/”应用程序中的服务器错误。rn参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。rnrn异常详细信息: System.Data.SqlClient.SqlException: 参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。rnrn源错误:rnrnrn行 110: SqlCommand cmd = new SqlCommand(sql, connection, transaction);rn行 111: cmd.Parameters.AddRange(values);rn行 112: int result = Convert.ToInt32(cmd.ExecuteScalar());rn行 113: return result;rn行 114: rnrnrn源文件: D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\DBHelper.cs 行: 112rnrn堆栈跟踪:rnrnrn[SqlException (0x80131904): 参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +946986rn System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +821638rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932rn System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31rn System.Data.SqlClient.SqlDataReader.get_MetaData() +62rn System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297rn System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32rn System.Data.SqlClient.SqlCommand.ExecuteScalar() +137rn DuoCaiDLL.DuoCaiDAL.DBHelper.GetScalar(String sql, SqlParameter[] values) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\DBHelper.cs:112rn DuoCaiDLL.DuoCaiDAL.AdminInfoService.AdminAdd(AdminInfo admin) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\AdminInfoService.cs:35rn DuoCaiDLL.DuoCaiBLL.AdminInfoManager.AdminAdd(AdminInfo admin) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiBLL\AdminInfoManager.cs:33rn DuoCaiApple.DuoCaiBackManageSystem.WebBack.Admin_Add.btnAdd_Click(Object sender, EventArgs e) in D:\我的文档\Desktop\DuoCai\DuoCaiApple\DuoCaiBackManageSystem\WebBack\Admin_Add.aspx.cs:44rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746rn

过程 'Up_Add_Users' 需要参数 '@User_Id',但未提供参数

07-02

存储过程代码如下:[code=SQL]CREATE PROCEDURE Up_Add_Usersrn(@User_Name varchar(20),@User_Pwd varchar(50),@User_Ask varchar(100),@User_Answer varchar(100),@User_Email varchar(200),rn@UserBase_Sex varchar(10),@UserBase_Birthday datetime,@UserBase_Seat varchar(200),@UserBase_Oicq varchar(15),@UserBase_Msn varchar(200),rn@UserBase_Pic varchar(200),@UserBase_Ink varchar(1000),@User_Id int out)rnASrnINSERT INTO [Users](User_Name,User_Pwd,User_Ask,User_Answer,User_Email,User_Online)rnVALUES(@User_Name,@User_Pwd,@User_Ask,@User_Answer,@User_Email,1)rnSELECT @User_Id = Max ([User_id]) FROM UsersrnINSERT INTO UserBase (UserBase_UserId)VALUES(@User_Id)rnINSERT INTO UserState (UserState_UserId)VALUES(@User_Id)rnEXEC Up_Change_UserBase @User_Id,@UserBase_Sex,@UserBase_Birthday,@UserBase_Seat,@UserBase_Oicq,@UserBase_Msn,@UserBase_Pic,@UserBase_Inkrn/* --------------------论坛信息表 ----------------------*/rnUPDATE Bbs_SiteInfo SET SiteInfo_UserCount = SiteInfo_UserCount +1 ,SiteInfo_NewUserId =@User_Id,SiteInfo_NewUserName=@User_Name WHERE SiteInfo_Id = 1rnrnGOrn[/code]rnrn[color=#0000FF]我在asp.net中的调用此存储过程添加对数的代码如下:rn[code=C#]SqlCommand cmdForum = new SqlCommand("Up_Add_Users", connForum);rn cmdForum.CommandType = CommandType.StoredProcedure;rn rn cmdForum.Parameters.Add("@User_Name", userName);rn cmdForum.Parameters.Add("@User_Pwd", MD5(pwd));rn cmdForum.Parameters.Add("@User_Ask", "0");rn cmdForum.Parameters.Add("@User_Answer", "我的生意网");rn cmdForum.Parameters.Add("@User_Email", mail);rn cmdForum.Parameters.Add("@UserBase_Sex", "boy");rn cmdForum.Parameters.Add("@UserBase_Birthday", DateTime.Now.ToString());rn cmdForum.Parameters.Add("@UserBase_Seat", "中国");rn cmdForum.Parameters.Add("@UserBase_Oicq", "312112153");rn cmdForum.Parameters.Add("@UserBase_Msn", "msn@hotmail.com");rn cmdForum.Parameters.Add("@UserBase_Pic", "images/user.gif");rn cmdForum.Parameters.Add("@UserBase_Ink", "我的个性签名");rn //cmdForum.Parameters.Add("@User_Id",)rnrn connForum.Open();rn cmdForum.ExecuteNonQuery();[/code]rn我不知cmdForum.Parameters.Add("@User_Id",)处的参数怎么处理,请高手指教。[/color]rnrn我现在运行时的报错是:rn异常详细信息: System.Data.SqlClient.SqlException: 过程 'Up_Add_Users' 需要参数 '@User_Id',但未提供该参数。rnrn源错误: rnrnrn行 275:rn行 276: connForum.Open();rn行 277: cmdForum.ExecuteNonQuery();rn行 278: rn行 279:rn rnrn源文件: e:\n\my31net\member_reg.aspx.cs 行: 277 rn

过程需要参数“”但未提供参数!!存储过程的问题!求救!

11-12

做了个简单的三层,向数据库中添加东西,用得存储过程,因为不太熟悉,所以一直出现问题,但是我却不知道究竟什么地方出现了问题!请教大家!rnrnDAL层代码:[code=C#] public int InsertNews(Model.articlemodel SingleNews)rn rn rn string procname = "dbo.addnews";rn SqlParameter[] prames = rn new SqlParameter("@title",SqlDbType.NVarChar,50),rn new SqlParameter("@news_time",SqlDbType.DateTime),rn new SqlParameter("@news_from",SqlDbType.NVarChar,50),rn new SqlParameter("@news_class",SqlDbType.NVarChar,50),rn new SqlParameter("@news_content",SqlDbType.NVarChar,200);rn prames[0].Value = SingleNews.title;rn prames[1].Value = SingleNews.news_time;rn prames[2].Value = SingleNews.news_from;rn prames[3].Value = SingleNews.news_class;rn prames[4].Value = SingleNews.news_content;rn int intResult = DBUtility.DataBase.RunExecute(procname,prames);//后面注释部分rn return intResult;rn rn // public static int RunExecute(string procName, SqlParameter[] prames)rn rn SqlConnection conn = DBHelp.GetConn();rn SqlCommand cmd = new SqlCommand();rn cmd.CommandType = CommandType.StoredProcedure;rn cmd.Connection = conn;rn cmd.CommandText = procName;rn conn.Open();rn int intResult = cmd.ExecuteNonQuery();rn conn.Close();rn return intResult;rn rn rn rn [/code]rnrnBLL层:[code=C#]public bool InsertNews(string title,DateTime news_time,string news_from,string news_class,string news_content)rn rn bool Flage = false;rn Dal.articledal ee = new Dal.articledal();rn Model.articlemodel SingleNews = new Model.articlemodel();rn SingleNews.title = title;rn SingleNews.news_time = news_time;rn SingleNews.news_from = news_from;rn SingleNews.news_class = news_class;rn SingleNews.news_content = news_content;rn int intresult=ee.InsertNews(SingleNews);rn if (intresult > 0)rn rn Flage = true;rn rn rn return Flage;rn [/code]rnrnWEB层:[code=C#]protected void BtnAddNews_Click(object sender, EventArgs e)rn rn string title = this.Txttitle.Text;rn DateTime news_time = System.DateTime.Now;rn string news_from = this.Txtnewsfrom.Text;rn string news_class = this.DropDownList1.SelectedValue;rn string news_content = this.Txtnewscontent.Text;rn Bll.articlebll bll = new Bll.articlebll();rn bool s=bll.InsertNews(title,news_time,news_from,news_class,news_content);rn rn if (s)rn rn LabMessage.Text = "添加新闻成功!";rn rn elsern rn LabMessage.Text = "抱歉,新闻添加失败!";rn rn rn [/code]rnrn存储过程如下:rn ALTER PROCEDURE dbo.addnews rn rn (rn @title nvarchar(50)=erererrwrwer,rn @news_time datetime,rn @news_from nvarchar(50)=dgdgdgdfg,rn @news_class nvarchar(50)=dfdgdgfgfg,rn @news_content nvarchar(200)=fggggggggrn )rn rnASrn insert into article(title,news_time,news_from,news_class,news_content) values(@title,@news_time,@news_from,@news_class,@news_content)rn RETURNrn(应该是参数没有传递给存储过程,但是我看了半天也没有发现究竟哪里的代码出现了问题,请帮忙看一下,你的举手之劳,就能解决我好几天的困惑!谢谢)

求助!!!过程 'dnt_updateuserprofile' 需要参数 '@realname',但未提供参数

07-18

“/bbs”应用程序中的服务器错误。rn--------------------------------------------------------------------------------rnrn过程 'dnt_updateuserprofile' 需要参数 '@realname',但未提供该参数。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.SqlClient.SqlException: 过程 'dnt_updateuserprofile' 需要参数 '@realname',但未提供该参数。rnrn源错误: rnrnrn[没有相关的源行]rn rnrn源文件: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\bbs\c17489bf\ee9e7af6\sojnjemk.0.cs 行: 0 rnrn堆栈跟踪: rnrnrn[SqlException: 过程 'dnt_updateuserprofile' 需要参数 '@realname',但未提供该参数。]rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742rn System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +194rn Discuz.Common.Database.ExecuteNonQuery(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)rn Discuz.Common.Database.ExecuteNonQuery(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters)rn Discuz.Common.Database.ExecuteNonQuery(CommandType commandType, String commandText, SqlParameter[] commandParameters)rn Discuz.Forum.UserFactory.UpdateUserProfile(UserInfo __userinfo)rn Discuz.ForumPage.usercpprofile.ShowPage() +1346rn Discuz.Forum.BasePage..ctor()rn Discuz.ForumPage.usercpprofile..ctor() +4rn ASP.usercpprofile_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\bbs\c17489bf\ee9e7af6\sojnjemk.0.cs:0rnrn[TargetInvocationException: 调用的目标发生了异常。]rn System.RuntimeType.CreateInstanceImpl(Boolean publicOnly) +0rn System.Activator.CreateInstance(Type type, Boolean nonPublic) +66rn System.Web.UI.TemplateControlParser.GetCompiledInstance(String virtualPath, String inputFile, HttpContext context) +164rnrn[HttpException (0x80004005): 未能创建类型为“ASP.usercpprofile_aspx”的页。]rn System.Web.UI.TemplateControlParser.GetCompiledInstance(String virtualPath, String inputFile, HttpContext context) +341rn System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String virtualPath, String inputFile, HttpContext context) +43rn System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path) +44rn System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +699rn System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +95rn System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173rnrn rnrnrn--------------------------------------------------------------------------------rn版本信息: Microsoft .NET Framework 版本:1.1.4322.2407; ASP.NET 版本:1.1.4322.2407

过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供参数

05-18

最近在做考试系统时碰到这个问题了,好郁闷,弄了好久也没解决,请大家帮我看一下,不胜感激!rnrnrn错误提示信息如下:rn过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。rn异常详细信息: System.Data.SqlClient.SqlException: 过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。rn源错误: rn行 299: SqlDataAdapter adapter = new SqlDataAdapter(Cmd);rn行 300: DataSet dataset = new DataSet();rn[color=#FF9900]行 301: adapter.Fill(dataset);[/color]行 rn302: Close();rn行 303: return dataset;rn ----------------------------------------------------------------rn表UserAnswer:rnID int rnUserID varcharrnPaperID intrnType varcharrnTitleID intrnMark intrnUserAnswer varcharrnExamTime datetimernrn-----------------------------------------rn这是存储过程rnCREATE PROCEDURE [dbo].[Proc_UserAnswer] rn @PaperID [int], rn @Type [varchar](10),rn @UserID [varchar](50)rnASrnbegin rn declare @sql nvarchar(1000)rnif @Type='单选题' rn begin rn set @sql='select * from UserAnswer,SingleProblemrn where [Type]=''单选题'' and rn UserAnswer.TitleID=SingleProblem.ID and rn [PaperID]= +Cast(@PaperID AS varchar(10) andrn UserID=@UserID'rn exec sp_executesql @sql rn endrnelse if @Type='多选题' rn begin rn set @sql='select * from UserAnswer,MultiProblemrn where [Type]=''多选题'' and rn UserAnswer.TitleID=MultiProblem.ID and rn [PaperID]= +Cast(@PaperID AS varchar(10) and rn UserID=@UserID'rn exec sp_executesql @sql rn endrnelse if @Type='判断题' rn begin rn set @sql='select * from UserAnswer,JudgeProblemrn where ( [Type]=''判断题'' andrn UserAnswer.TitleID=JudgeProblem.ID and rn [PaperID]= +Cast(@PaperID AS varchar(10) and rn UserID=@UserID)'rn exec sp_executesql @sql rn endrnelse if @Type='填空题' rn begin rn set @sql='select * from UserAnswer,FillBlankProblemrn where ( [Type]=''填空题'' and rn UserAnswer.TitleID=FillBlankProblem.ID and rn [PaperID]= +Cast(@PaperID AS varchar(10) and rn UserID=@UserID)'rn exec sp_executesql @sql rn endrnelse if @Type='问答题' rn begin rn set @sql='select * from UserAnswer,QuestionProblemrn where ( [Type]=''问答题'' and rn UserAnswer.TitleID=QuestionProblem.ID and rn [PaperID]= +Cast(@PaperID AS varchar(10) and rn UserID=@UserID)'rn exec sp_executesql @sql rn endrnendrnGOrn-------------------------------------------------rn 类文件Paper.cs:rnrn //查询某个用户考试的试卷,rn public DataSet QueryUserPaper(int paperid,string type,string userid)rn rn DataBase DB = new DataBase();rn SqlParameter[] Params = new SqlParameter[3];rn Params[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid); //试卷编号rn Params[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, type); //题目类型 rn Params[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid); //用户ID rnrn return DB.GetDataSet("Proc_UserAnswer", Params);rn rnrn------------------------------------rnDataBase.cs文件:rn public DataSet GetDataSet(string ProcName, SqlParameter[] Params)rn rn Open();rn SqlCommand Cmd = CreateCommand(ProcName, Params);rn SqlDataAdapter adapter = new SqlDataAdapter(Cmd);rn DataSet dataset = new DataSet();rn adapter.Fill(dataset);rn Close();rn return dataset;rn rnrn---------------------------------------rn查看某个用户的试卷回答,UserPaper.aspx.cs:rn DataBase DB = new DataBase();rn DataSet ds = DB.GetDataSetSql("select * from [UserAnswer] where PaperID='" + Request.QueryString["PaperID"] + "'");rn DataRow[] row = ds.Tables[0].Select();rn foreach (DataRow rs in row)rn rn userid = rs["UserID"].ToString();rn examtime = Convert.ToDateTime(rs["ExamTime"].ToString());rn rnrnint paperID = Convert.ToInt32(Request.QueryString["PaperID"].ToString()); rnrn Paper paper =new Paper();rnrn DataSet ds1 = paper.QueryUserPaper(paperID, "单选题", userid);rn GridView1.DataSource = ds1;rn GridView1.DataBind();rn ((Label)GridView1.HeaderRow.FindControl("Label27")).Text = ((Label)GridView1.Rows[0].FindControl("Label4")).Text;rnrnrn DataSet ds2 = paper.QueryUserPaper(paperID, "多选题", userid);rn GridView2.DataSource = ds2;rn GridView2.DataBind();rn ((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;

过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供参数

05-19

请大家用帮我看看.过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。是不是下面的存储过程哪里错了??rnrnUserID= '+@UserID +'这么写有没有错啊??rnrn-------------------------------------------rnCREATE PROCEDURE [dbo].[Proc_UserAnswer] rn (@PaperID int, rn @Type varchar(10),rn @UserID varchar(50))rnASrnbegin rn declare @sql nvarchar(1000)rnif @Type='单选题' rn begin rn set @sql='select * from UserAnswer,SingleProblemrn where [Type]=''单选题'' and rn UserAnswer.TitleID=SingleProblem.ID and UserID= '+@UserID +' and rn [PaperID]= '+Cast(@PaperID AS varchar(10)) rn exec sp_executesql @sql rn endrnelse if @Type='多选题' rn begin rn set @sql='select * from UserAnswer,MultiProblemrn where [Type]=''多选题'' and rn UserAnswer.TitleID=MultiProblem.ID and UserID= ' +@UserID +' and rn [PaperID]= ' +Cast(@PaperID AS varchar(10)) rn exec sp_executesql @sql rn endrnendrnGOrnrnrn--------------------------------------------rn堆栈跟踪: rnrnrn[SqlException (0x80131904): 过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857322rn System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734934rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838rn System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31rn System.Data.SqlClient.SqlDataReader.get_MetaData() +62rn System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297rn System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122rn System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12rn System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7rn System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141rn System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137rn System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +86rn OnLineExam.DataAccessLayer.DataBase.GetDataSet(String ProcName, SqlParameter[] Params) in c:\Inetpub\wwwroot\OnLineExam\App_Code\DataAccessLayer\DataBase.cs:301rn Web_UserPaper.InitData() in c:\Inetpub\wwwroot\OnLineExam\Web\UserPaper.aspx.cs:50rn Web_UserPaper.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\OnLineExam\Web\UserPaper.aspx.cs:26rn System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15rn System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34rn System.Web.UI.Control.OnLoad(EventArgs e) +99rn System.Web.UI.Control.LoadRecursive() +47rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061rnrn rn

没有更多推荐了,返回首页