2009-07-28 16 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(); 
相關問題