[英]LastInsertedId in Npgsql(PostgreSQL)
這對於 Postgresql 來說如何正確? LastInsertedId 上的錯誤
int playerId = 0;
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
try
{
connection.Open();
NpgsqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO users (name) VALUES (@playerName)";
command.Parameters.AddWithValue("@playerName", playerModel.realName);
command.ExecuteNonQuery();
// Get the inserted identifier LastInsertedId
playerId = (int)command.LastInsertedId;
command.Parameters.AddWithValue("@playerId", playerId);
}
catch (Exception ex)
{
//
}
}
command.CommandText = "INSERT INTO users (name) VALUES (@playerName) RETURNING id";
playerId = (int)command.ExecuteScalar();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.