views:

803

answers:

6

How do you execute a stored procedure in subsonic 3.0 that returns a value? For example many of my stored procedures return @@identity, and I can't figure out how to access that value without re querying the table. Again, not an output parameter, but a return value.

+5  A: 
StoredProcedure sproc = db.FancySchmancySproc();
sproc.Execute();
int output = (int)sproc.Output; // returns type 'object' so you'll need to cast
John Sheehan
A: 

That is what I thought, but sproc.output is always null. I wonder if there's a bug in the latest version 3.0.0.3

mafudge
+1  A: 
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;

}
Pedro Tiago Pereira
A: 
StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteDataSet();
+1  A: 

This works for me:

StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteScalar<int>();
rball
A: 

sproc.ExecuteDataSet() returns an error

The SelectCommand property has not been initialized before calling 'Fill'.

please help

aous