Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
-----------
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 );
    }
Posted
Updated 30-Dec-10 8:57am
v2
Comments
[no name] 30-Dec-10 14:58pm    
Formatted code blocks

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.
 
Share this answer
 
v2
Comments
sathish.jampala 30-Dec-10 22:54pm    
hello sir. thanks for ur reply.
Hi,

Did you provide the entire code snippet? like what does this function BusinessLogic.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
 
Share this answer
 
v2
Comments
sathish.jampala 30-Dec-10 22:55pm    
hello sir. i tried in this way also. but it is displaying empty in the dataset. string does not displaying on label.
is there any solution plz tell me.

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



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