2009-07-28 36 views

回答

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

这就是我的想法,但sproc.output始终为空。我不知道是否有在最新的版本中的错误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

这个工作对我来说:

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

好吧......我是有什么约翰·希恩说工作,突然它刚刚开始给我一个例外。

我只是用以下SP进行测试。


SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE TestLocal

@a数字(18,0) AS

BEGIN

SET NOCOUNT ON;

返回10

END

GO


和我的在C#代码是下面


StoredProcedure的SP =新DB()。TestLocal(1) ;

sp.Execute();

int timeLeft =(int)sp.Output;

return timeLeft;


编辑1:

我把它做以下工作,但我不认为这是应该做的正确方法。


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

sp.Command.AddReturnParameter();

sp.Execute();

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

return myReturnValue;

1

我一直在使用ActiveRecord运行存储过程,像这样;

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