SQLHelper Stored Procedure Output Parameter

R

rockdale

Hi, All
How to get the output parameter's value when you use the SQLHelper
(Microsoft Data Access Block)?

When I try to access my ourput parm I got the following error.

System.NullReferenceException: Object reference not set to an instance
of an object.

I thought it is because there is a statement cmd.Parameters.Clear() in
ExecuteNonQuery function, but even I comment this parameter clear
statement, it still caught the same error.

Before ExecuteNonQuery return, The output value is still in the output
parm. but when return to SqlHelper.ExecuteNonQuery(), the output
parameter value got lost while the vlaue of input parameter is still
there.

Did I miss something? Or SQLHelper can not return output parameter?

Help Please

---------------------------------------------------------------------------------------------
public string TestOutput(int pFlag){
SqlParameter[] parm = new SqlParameter[3];

parm[0] = new SqlParameter("@flag", SqlDbType.Int,4);
parm[0].Value = pFlag;
parm[1] = new SqlParameter("@result_txt", SqlDbType.VarChar,32);
parm[1].Direction = ParameterDirection.InputOutput;
parm[2] = new SqlParameter("@result_txt", SqlDbType.Int,4);
parm[2].Direction = ParameterDirection.InputOutput;
// parm[2].Direction = ParameterDirection.Output;



SqlHelper.ExecuteNonQuery(ConnectionString, "UDSP_OUTPUT_TEST",
parm);

return parm[1].Value.ToString();


}



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



CREATE PROCEDURE UDSP_OUTPUT_TEST
@flag int,
@result_txt varchar (32) output,
@result_code int output
AS
begin

set nocount on
if @flag=1
begin
select @result_txt = 'ERROR RETURNED FROM SP'
select @result_code = -1
return
end
else
begin
select @result_txt = 'SUCCEED RETURNED FROM SP'
select @result_code = 0

end

set nocount off

end
 
Joined
Jan 15, 2009
Messages
1
Reaction score
0
i got problem same you
and i try by insert parameter type and it work

SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,"UDSP_OUTPUT_TEST",
parm);

=== sample ====

SqlParameter spc = new SqlParameter[4];
spc = SqlHelperParameterCache.GetSpParameterSet(
cnn,
"GetProductsByCategory");

spc[0]=productID //Input Parameter
spc[1]=productName //Output Parameter
spc[2]=unitPrice //Output Parameter
spc[3]=qtyPerUnit //Output Parameter

SqlHelper.ExecuteNonQuery(
cnn,
CommandType.StoredProcedure,
"GetProductDetails",
spc);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top