【发布时间】:2011-04-07 15:02:41
【问题描述】:
我',尝试使用串行主键向 PostgreSQL 表中插入一行,我需要在插入后检索该列。我得到了这样的东西:
“pais”表有 3 列:id、pais、capital; id 是一个序列列,是它的主键。
NpgsqlCommand query = new NpgsqlCommand("insert into pais(nombre, capital) values(@nombre, @capital)", conn);
query.Parameters.Add(new NpgsqlParameter("nombre", NpgsqlDbType.Varchar));
query.Parameters.Add(new NpgsqlParameter("capital", NpgsqlDbType.Varchar));
query.Prepare();
query.Parameters[0].Value = this.textBox1.Text;
query.Parameters[1].Value = this.textBox2.Text;
Object res = query.ExecuteScalar();
Console.WriteLine(res);
它在表中插入行,但“res”值为空。如果我用 nexval('table_sequence') 插入也返回 null。
知道如何返回表的 id 吗?我错过了什么?
提前致谢
【问题讨论】:
-
你应该在 StackOverflow 上问这个问题。
-
所以。程序员是干什么的?
标签: c# postgresql