2009-07-28 4 views

Antwort

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

Das ist, was ich dachte, aber sproc.output ist immer null. Ich frage mich, ob es ein Fehler in der neuesten Version 3.0.0.3

1
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; 

} 
0
StoredProcedure sproc = db.FancySchmancySproc(); 
sproc.ExecuteDataSet(); 
1

Dies funktioniert für mich:

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

Ok ... ich hatte es arbeitet mit dem, was John Sheehan sagte, plötzlich es hat gerade angefangen, mir eine Ausnahme zu geben.

Ich teste gerade mit dem folgenden SP.


SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE TestLocal

@a numeric (18,0) AS

BEGIN

SET NOCOUNT ON;

return 10

END

GO


und meinen Code in C# ist die folgende


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

sp.Execute();

int timeLeft = (int) sp.Output;

RücklaufzeitLinks;


Edit 1:

Ich habe es, indem Sie folgende arbeiten, aber ich glaube nicht, das ist der richtige Weg, es zu tun.


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

sp.Command.AddReturnParameter();

sp.Execute();

int meinReturnValue = (int) sp.Command.Ausgabewerte [0];

Rückgabe myReturnValue;

1

Ich habe gespeicherte Procs mit ActiveRecord wie folgt ausgeführt;

// 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(); 
Verwandte Themen