【发布时间】:2009-07-28 17:56:48
【问题描述】:
如何在 subsonic 3.0 中执行一个返回值的存储过程?例如,我的许多存储过程都返回@@identity,而我不知道如何在不重新查询表的情况下访问该值。同样,不是输出参数,而是返回值。
【问题讨论】:
如何在 subsonic 3.0 中执行一个返回值的存储过程?例如,我的许多存储过程都返回@@identity,而我不知道如何在不重新查询表的情况下访问该值。同样,不是输出参数,而是返回值。
【问题讨论】:
StoredProcedure sproc = db.FancySchmancySproc();
sproc.Execute();
int output = (int)sproc.Output; // returns type 'object' so you'll need to cast
【讨论】:
这对我有用:
StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteScalar<int>();
【讨论】:
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;
}
【讨论】:
好吧......我已经按照 John Sheehan 所说的进行了操作,但突然间它开始给我一个例外。
我只是在用下面的 SP 进行测试。
设置 ANSI_NULLS ON 去 设置 QUOTED_IDENTIFIER ON 去 创建程序TestLocal
@a 数字(18,0) 作为
开始
设置无计数;
返回 10
结束
去
我的 C# 代码如下
StoredProcedure sp = new DB().TestLocal(1);
sp.Execute();
int timeLeft = (int)sp.Output;
返回时间;
编辑 1:
我通过执行以下操作使其正常工作,但我认为这不是正确的方法。
StoredProcedure sp = new DB().TestLocal(1);
sp.Command.AddReturnParameter();
sp.Execute();
int myReturnValue = (int)sp.Command.OutputValues[0];
返回我的返回值;
【讨论】:
我一直在像这样使用 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();
【讨论】:
这是我的想法,但 sproc.output 始终为空。不知道最新版本3.0.0.3有没有bug
【讨论】:
StoredProcedure sproc = db.FancySchmancySproc();
sproc.ExecuteDataSet();
【讨论】: