0
I',試圖插入一行到串行主鍵PostgreSQL表,我需要插入後檢索此列。我有這樣的事情:ExecuteScalar問題與Npgsql插入
表「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?我錯過了什麼?
在此先感謝
應該在SO – TheLQ 2011-04-07 15:13:58
你應該在StackOverflow上提出這個問題。 – 2011-04-07 15:14:07
所以。程序員是關於什麼的? – Cheluis 2011-04-07 15:21:07