Retrieve serial ID with Npgsql when inserting with ExecuteScalar

后端 未结 4 1318
醉酒成梦
醉酒成梦 2020-12-16 19:08

I\'m trying to insert a row into a PostgreSQL table with a serial primary key and I need to retrieve this column after it was inserted. I got something like this:

Th

4条回答
  •  遥遥无期
    2020-12-16 20:05

    insert into pais(nombre, capital) values(@nombre, @capital) RETURNING id
    

    replace id with your primary keyenter code here and use

    Object res = query.ExecuteScalar();
    

    Inside res you'll have the PK.

提交回复
热议问题