Retrieve last id from Firebird db table

2019-02-20 15:30发布

retreiving last inserted id

I want to retreive last inserted id from firebird database. Data is succ. inserted, trigger inserts id as it should using generator.

I'm advised to use this syntax

 var sql = "INSERT INTO ... VALUES ...  " +
           "RETURNING Id";

where RETURNING Id should return table Id.

I dont know how to store into variable.

int lastId = ...

标签: c# .net firebird
1条回答
Bombasti
2楼-- · 2019-02-20 16:14
var con = OpenFB2Connection();
var trans = con.BeginTransaction();

var command = new OleDbCommand("INSERT INTO ... VALUES ...  RETURNING Id");

cmd.Parameters.Add("Id", OleDbType.Integer).Direction = ParameterDirection.Output;


var Id = (int)cmd.ExecuteScalar(); //Here is your Id
查看更多
登录 后发表回答