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

gdjlc 2008-05-19 02:46:32
请大家用帮我看看.过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。是不是下面的存储过程哪里错了??

UserID= '+@UserID +'这么写有没有错啊??

-------------------------------------------
CREATE PROCEDURE [dbo].[Proc_UserAnswer]
(@PaperID int,
@Type varchar(10),
@UserID varchar(50))
AS
begin
declare @sql nvarchar(1000)
if @Type='单选题'
begin
set @sql='select * from UserAnswer,SingleProblem
where [Type]=''单选题'' and
UserAnswer.TitleID=SingleProblem.ID and UserID= '+@UserID +' and
[PaperID]= '+Cast(@PaperID AS varchar(10))
exec sp_executesql @sql
end
else if @Type='多选题'
begin
set @sql='select * from UserAnswer,MultiProblem
where [Type]=''多选题'' and
UserAnswer.TitleID=MultiProblem.ID and UserID= ' +@UserID +' and
[PaperID]= ' +Cast(@PaperID AS varchar(10))
exec sp_executesql @sql
end
end
GO


--------------------------------------------
堆栈跟踪:


[SqlException (0x80131904): 过程 'Proc_UserAnswer' 需要参数 '@UserID',但未提供该参数。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857322
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734934
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +86
OnLineExam.DataAccessLayer.DataBase.GetDataSet(String ProcName, SqlParameter[] Params) in c:\Inetpub\wwwroot\OnLineExam\App_Code\DataAccessLayer\DataBase.cs:301
Web_UserPaper.InitData() in c:\Inetpub\wwwroot\OnLineExam\Web\UserPaper.aspx.cs:50
Web_UserPaper.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\OnLineExam\Web\UserPaper.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


...全文
486 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdjlc 2008-05-19
  • 打赏
  • 举报
回复
多谢大家的指点,特别是songhuan 的热心帮助,问题已经解决了,我原来的代码是没问题的,只是我在下面存储过程写多了1个左括号,我把where [Type]=''问答题'' and 不小心写成了where ( [Type]=''问答题'' and 等,虽然语法检查成功,但最后结果老是出错,终于可以睡个安稳觉了..



---------------------------------------

CREATE PROCEDURE [dbo].[Proc_UserAnswer]
(@PaperID int,
@Type varchar(10),
@UserID varchar(50))
AS
begin
declare @sql nvarchar(1000)
if @Type='单选题'
begin
set @sql='select * from UserAnswer,SingleProblem
where [Type]=''单选题'' and
UserAnswer.TitleID=SingleProblem.ID and [PaperID]= ' +Cast(@PaperID AS varchar(10)) + ' and
[UserID]= ' + @UserID
exec sp_executesql @sql

end
else if @Type='多选题'
begin
set @sql='select * from UserAnswer,MultiProblem
where [Type]=''多选题'' and
UserAnswer.TitleID=MultiProblem.ID and [PaperID]= ' +Cast(@PaperID AS varchar(10)) + ' and
[UserID]= ' + @UserID
exec sp_executesql @sql
end
else if @Type='判断题'
begin
set @sql='select * from UserAnswer,JudgeProblem
where [Type]=''判断题'' and
UserAnswer.TitleID=JudgeProblem.ID and [PaperID]= ' +Cast(@PaperID AS varchar(10)) + ' and
[UserID]= ' + @UserID
exec sp_executesql @sql
end
else if @Type='填空题'
begin
set @sql='select * from UserAnswer,FillBlankProblem
where [Type]=''填空题'' and
UserAnswer.TitleID=FillBlankProblem.ID and [PaperID]= ' +Cast(@PaperID AS varchar(10)) + ' and
[UserID]= ' + @UserID
exec sp_executesql @sql
end
else if @Type='问答题'
begin
set @sql='select * from UserAnswer,QuestionProblem
where [Type]=''问答题'' and
UserAnswer.TitleID=QuestionProblem.ID and [PaperID]= ' +Cast(@PaperID AS varchar(10)) + ' and
[UserID]= ' + @UserID
exec sp_executesql @sql
end

end
GO
anlen26 2008-05-19
  • 打赏
  • 举报
回复
调试监控Params1[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid); 里的userid,应该是null了,检查userid变量的赋值
songhuan 2008-05-19
  • 打赏
  • 举报
回复
string Type="单选题";
string UserID=1;
int PaperID = Convert.ToInt32(Request.QueryString["PaperID"].ToString());

SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
Connection.Open();
//SqlCommand cmd1 = new SqlCommand("Proc_UserAnswer", Connection);
SqlCommand cmd1 = new SqlCommand(Connection);
cmd1.CommandText="exec Proc_UserAnswer @PaperID="+PaperID+" ,@Type='"+Type+"',@UserID='"+UserID+"'";
//cmd1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
GridView1.DataSource = ds1;
GridView1.DataBind();
gdjlc 2008-05-19
  • 打赏
  • 举报
回复
songhuan (烟花公子)大哥,能不能说详细点,我刚学不久,很多东西不懂的.
string cmd="exec Proc_UserAnswer @PaperID="+PaperID+" ,@Type='"+TypeCode+"',@UserID='"+UserID+"'";
这句应该放在下面代码什么地方呢?在线急等,谢了.....

------------------------------------------------
string Type="单选题";
string UserID=1;
int PaperID = Convert.ToInt32(Request.QueryString["PaperID"].ToString());

SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
Connection.Open();
SqlCommand cmd1 = new SqlCommand("Proc_UserAnswer", Connection);
cmd1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
GridView1.DataSource = ds1;
GridView1.DataBind();
songhuan 2008-05-19
  • 打赏
  • 举报
回复
调用的时候可以简单这样写,

exec Proc_UserAnswer @PaperID=1 ,@Type='a',@UserID='ppp'

int PaperID=1;
string TypeCode="a";
string UserID="ppp";
string cmd="exec Proc_UserAnswer @PaperID="+PaperID+" ,@Type='"+TypeCode+"',@UserID='"+UserID+"'";

gdjlc 2008-05-19
  • 打赏
  • 举报
回复
我已经调用存储过程了,
DataBase DB = new DataBase();
SqlParameter[] Params1 = new SqlParameter[3];
Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, PaperID);
Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "单选题");
Params1[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
DataSet ds1 = DB.GetDataSet("Proc_UserAnswer", Params1);
GridView1.DataSource = ds1;
GridView1.DataBind();
------------------------------------
存储过程语法检查是成功的,UserID= @UserID这句最后也是提示需要参数 '@UserID', 请大家再帮帮忙....
anheizhizi 2008-05-19
  • 打赏
  • 举报
回复
你程序里添加了@UserID了么?
周公 2008-05-19
  • 打赏
  • 举报
回复
调用这个存储过程的时候没有给它传参数值。
wxg22526451 2008-05-19
  • 打赏
  • 举报
回复
UserID= '+@UserID +'这么写有没有错啊??
------->
UserID= @UserID

另外程序中调用此存储过程,
也得注意传入这个参数,并赋值
Jinglecat 2008-05-19
  • 打赏
  • 举报
回复
给Command添加过程参数了吗?

mySqlCommand.Parameters.Add("@UserID", SqlDbType.Varchar, 50).Value = "Hello911";

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧