Subsonic 3 - how do you execute a stored procedure that returns a value?

How to execute a stored procedure in subsonic 3.0 that returns a value? For example, many of my stored procedures return the @@ identifier, and I cannot figure out how to access this value without re-querying the table. Again, not the output parameter, but the return value.

+3
source share
7 answers
StoredProcedure sproc = db.FancySchmancySproc();
sproc.Execute();
int output = (int)sproc.Output; // returns type 'object' so you'll need to cast
+4
source
StoredProcedure sp = SPs.TestProcedure(0);

sp.Command.AddReturnParameter();

object retValue = sp.Command.Parameters.Find(delegate(QueryParameter p)
{ 
  return p.Mode == ParameterDirection.ReturnValue; 
}).ParameterValue;

if (retValue!=null)
{

  // cast the value to the type expected

  int rc = (int) retValue;

}
+1
source

:

StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteScalar<int>();
+1

... , , .

SP.


SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON TestLocal

@a (18,0) AS

SET NOCOUNT ON;

return 10


#


StoredProcedure sp = DB(). TestLocal (1);

sp.Execute();

int timeLeft = (int) sp.Output;

return timeLeft;


Change 1:

I got this by following these steps, but I don't think this is the correct way.


StoredProcedure sp = new DB (). TestLocal (1);

sp.Command.AddReturnParameter ();

sp.Execute ();

int myReturnValue = (int) sp.Command.OutputValues ​​[0];

return myReturnValue;

+1
source

I ran stored procs using ActiveRecord, for example:

// Connect to DB and run the stored proc into a dataset
myDatabasedb db = new myDatabasedb();
DataSet ds = db.myStoredProc(firstparam, secondparam, etc);

// Now you can do what you like with the dataset!
Gridview1.datasource = ds.executeDataSet();
+1
source

This is what I thought, but sproc.output is always null. I wonder if there is an error in the latest version 3.0.0.3

0
source
StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteDataSet();
0
source

Source: https://habr.com/ru/post/1713782/


All Articles