Firebird insert…returning asp.net

一个人想着一个人 提交于 2019-12-13 01:27:29

问题


I'm using Firebird 2.5 and asp.net (4.5).

I'm trying to find out how to use insert ... returning, or some equivalent.

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.

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?

Thanks

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)

回答1:


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


来源:https://stackoverflow.com/questions/15681172/firebird-insert-returning-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!