views:

267

answers:

3

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
     Select 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?

+1  A: 

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;
Michał Niklas
yes, but we can also use OUT parameter.
Ishita
A: 

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?

GDalma
This question is tagged Oracle, not SQL Server, so that's what I targeted my answer towards. Oracle does not (by default) serialize reads which is a good thing for scaleable applications. As WW stated in their comment a sequence in the best way of generating a primary key. See this link for the discussion which referenced the earlier link... http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4343369880986
Paul James
Thanks Paul, it was a honest question, I got doubts after what you said in the first place
GDalma
@GDalma - This is the right place to ask questions, best to learn from other peoples mistakes :)
Paul James
A: 

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

priyanka.sarkar