开发者

How to get stored procedure's returning value?

开发者 https://www.devze.com 2022-12-10 14:01 出处:网络
I have made stored procedures in oracle. I\'m calling it through my asp.net code. The procedure is : PROCEDURE prc_GetNewQuestionNo(iNextQuestionNo IN OUT NUMBER)

I have made stored procedures in oracle.

I'm calling it through my asp.net code.

The procedure is :

 PROCEDURE prc_GetNewQuestionNo(iNextQuestionNo IN OUT NUMBER)
 IS
    iQuestionNo NUMBER ;

 BEGIN
     Se开发者_如何学运维lect MAX(QUESTIONNO)+ 1 INTO iQuestionNo
     from tblIFFCOQUESTIONMASTER;
     iNextQuestionNo:=iQuestionNo;
 END prc_GetNewQuestionNo;

and I'm calling it in asp.net:

<Connection>
  com.CommandType = CommandType.StoredProcedure;
                com.CommandText = StoredProcedures.GET_NEW_QUESTION_NO;
                com.Parameters.Add(new OracleParameter("iNextQuestionNo", OracleType.Number)).Direction = ParameterDirection.InputOutput;

                adp = new OracleDataAdapter(com);
                ds = new DataSet();
                adp.Fill(ds);

How to get its return value?


Isn't it better to use function? Just like:

create function prc_GetNewQuestionNo(iNextQuestionNo IN NUMBER)
return number AS
    iQuestionNo NUMBER ;
BEGIN
    Select MAX(QUESTIONNO)+ 1 INTO iQuestionNo from tblIFFCOQUESTIONMASTER;
    return iQuestionNo;
END prc_GetNewQuestionNo;


I wanted to add a comment/question to your reply there Paul, but I couldnt. Apologize for my ignorance, but if you are using a SQL Server stored procedured with isolation level serializable, arent supposed all the sql tables to be locked for the time the transaction/stored procedure last, giving no problems of concurrency? is this a bad practice?


I guess the problem is here

                adp = new OracleDataAdapter(com);
                ds = new DataSet();
                adp.Fill(ds);

You want a scalar value and not an entire record set.. right? So instead try like this

//some code snippet

db.ExecuteNonQuery(cmd);               
iNextQuestionNo= (decimal?)cmd.Parameters[0].Value;

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消