1

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)
AjV Jsy
  • 5,799
  • 4
  • 34
  • 30
Steve Graham
  • 114
  • 2
  • 13
  • I removed my original answer Steve, hopefully someone will spot the unanswered question and step in. I tried adding extra info but the edit hasn't shown up :( – AjV Jsy Mar 29 '13 at 21:21

1 Answers1

0

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?;
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Thanks for your help, I didn't get this to work - same problem as before. Writing it as a stored procedure worked fine, so that's how I finished up. – Steve Graham Mar 31 '13 at 04:14