问题描述
我正在使用Firebird 2.5和asp.net(4.5).
I'm using Firebird 2.5 and asp.net (4.5).
我正在尝试找出如何使用insert ... returning或其他等效方法.
I'm trying to find out how to use insert ... returning, or some equivalent.
使用fbDataReader,它执行插入OK,但是无论如何我都无法访问返回的值.使用fbDataReader.GetName(0)似乎可以正常工作,可以在"returning"子句中返回变量名称.这甚至适用于子选择中的max():.....返回(从用户中选择max(userid)作为newid)返回文本"newid".我找不到该值的可用位置或位置.
Using fbDataReader, it executes the insert OK, but I can't find anyway of accessing a returned value. Using fbDataReader.GetName(0) seems to work ok, returning the variable name in the "returning" clause. This even applies to a max() in a subselect:..... returning (select max(userid) as newid from users)returns the text "newid".I can't find where, or whether, the value is available.
使用fbDataAdaptor填充DataTable,插入工作正常,但数据表似乎为空.
Using a fbDataAdaptor to fill a DataTable, the insert works OK, but data table seems empty.
有人知道这是否可行吗?如果可以,怎么做到的?
Does anyone know whether this is possible, and if so, how it's done?
谢谢
编辑
提供的代码:
EDIT
Code supplied :
strConn = ....
dbConn = New FirebirdSql.Data.FirebirdClient.FbConnection(strConn)
dbConn.Open()
MySQL = "insert into users (Firstname, Lastname) VALUES (@fname,@lname) returning userid"
FbC = New FirebirdSql.Data.FirebirdClient.FbCommand(MySQL, dbConn)
FbC.Parameters.Add("fname", FirebirdSql.Data.FirebirdClient.FbDbType.Text).Value = "Pete"
FbC.Parameters.Add("lname", FirebirdSql.Data.FirebirdClient.FbDbType.Text).Value = "Davis"
FbDataReader = FbC.ExecuteReader()
FbDataReader.Read()
TextBox1.Text = FbDataReader.GetName(0)
'TextBox1.Text = str(FbDataReader.GetInt64())
'TextBox1.Text = FbDataReader.GetString(0)
TextBox1.Text = FbDataReader.GetValue(0)
推荐答案
根据此线程 INSERT ... RETURNING ...
的行为类似于Firebird .NET提供程序的输出参数.因此,您将需要添加一个输出参数.
According to this thread INSERT ... RETURNING ...
behaves like output parameters for the Firebird .NET provider. So you will need to add an output parameter.
所以下面的代码应该可以工作:
So something like the code below should work:
FbParameter outParam = new FbParam("userid", FbDbType.Integer)
{
Direction = ParameterDirection.Output
};
FbC.Parameters.Add(outParam);
FbC.ExecuteNonQuery();
int? userId = outParam.Value as int?;
这篇关于火鸟插入...返回asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!