[英]LastInsertedId in Npgsql(PostgreSQL)
How is this correct for Postgresql?这对于 Postgresql 来说如何正确? Error on LastInsertedId
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.