如何在aspx页面中检索存储过程的参数 [英] how to retrieve out parameter of a stored procedure in aspx page
本文介绍了如何在aspx页面中检索存储过程的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好先生.
我在存储过程中有一个字符串作为out参数.我想在我的aspx页面中显示此字符串.一切都完美.每当我执行存储过程时.它执行得很好.
但是每当我调试解决方案时.它不会进入数据集.
请参阅下面的代码,我的sp
任何身体请帮助我.
hello sir.
i have a string as out parameter in my storedprocedure. i want display this string in my aspx page. every thing perfect. when ever i execute the storedprocedure. it is executing perfectly.
but when ever i debug my solution. it is not coming to dataset.
see my sp, code below
any body plz help me.
ALTER proc [dbo].[sp_insert]
(
@eid int,
@ename nvarchar(50),
@image nvarchar(50),
@print nvarchar(max) output
)
as begin
set @print=''Records are inserted successfully''
insert into tab (eid , ename , image )
values
(
@eid,
@ename,
@image
)
end
aspx.cs
-----------
aspx.cs
-----------
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlParameter[] oparam = new SqlParameter[4];
oparam[0] = new SqlParameter("@eid", Txteid.Text);
oparam[1] = new SqlParameter("@ename", Txtename.Text);
FU.SaveAs("E:\\BackUpWebsites\\sri\\images\\" + FU.FileName);
Server.MapPath("images\\" + FU.FileName);
oparam[2] = new SqlParameter("@image", "E:\\BackUpWebsites\\sri\\images\\" + FU.FileName );
oparam[3] = new SqlParameter("@print", SqlDbType.NVarChar, 50);
ds = BusinessLogic.InsertDetails(oparam );
oparam[3].Direction = ParameterDirection.Output;
LblResult.Visible = true;
LblResult.Text = Convert.ToString ( oparam [3].Value );
}
推荐答案
为什么需要返回字符串?正确的方法是使用返回代码并在调用代码中中断它.
还有一种更好的设计是将值从表单传递到业务逻辑方法,然后在其中创建Sqlparamter.这就是nTier/nLayer设计的工作方式.
Why do you need to return a string? The proper way would be to use a return code and interrupt it in the calling code.
Also a better design would be to pass the values from your form to the business logic method and create the Sqlparamter there. This how nTier/nLayer designs work.
您是否提供了完整的代码段?像此功能BusinessLogic.InsertDetails
是做什么的?弄清一切真正有助于解决问题.根据您提供的代码,我可以看到您在执行DB操作后正在设置参数方向,这可能会导致您所面临的问题.您可以尝试一下,
Hi,
Did you provide the entire code snippet? like what does this functionBusinessLogic.InsertDetails
do? clarify everything really helps out to pint point the problem.According to your provided code I can see you are setting parameter direction after executing the DB operation and this might cause the issue that you are facing.You can try this instead,
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlParameter[] oparam = new SqlParameter[4];
oparam[0] = new SqlParameter("@eid", Txteid.Text);
oparam[1] = new SqlParameter("@ename", Txtename.Text);
FU.SaveAs("E:\\BackUpWebsites\\sri\\images\\" + FU.FileName);
Server.MapPath("images\\" + FU.FileName);
oparam[2] = new SqlParameter("@image", "E:\\BackUpWebsites\sri\images\" + FU.FileName );
oparam[3] = new SqlParameter("@print", SqlDbType.NVarChar, 50);
oparam[3].Direction = ParameterDirection.Output;
ds = BusinessLogic.InsertDetails(oparam );
LblResult.Visible = true;
LblResult.Text = Convert.ToString ( oparam [3].Value );
}
希望对您有所帮助
Hope this will help
这篇关于如何在aspx页面中检索存储过程的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文