Retrieve last id from Firebird db table

我怕爱的太早我们不能终老 提交于 2020-01-11 07:17:49

问题


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 = ...

回答1:


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


来源:https://stackoverflow.com/questions/20271814/retrieve-last-id-from-firebird-db-table

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