using (SqlConnection conn = new SqlConnection(connectionString))
{
string sqlText = "INSERT INTO [Library] (Title, Tags, Body) OUTPUT INSERTED.[Id] VALUES(@Title, @Tags, @Body)";
using (SqlCommand cmd = new SqlCommand(sqlText, conn))
{
cmd.Parameters.AddWithValue("Title", title);
cmd.Parameters.AddWithValue("Tags", tags);
cmd.Parameters.AddWithValue("Body", body);
try
{
conn.Open();
Guid insertedGuid = (Guid)await cmd.ExecuteScalarAsync(); // <-- созданный GUID
}
finally
{
conn.Close();
}
} // using cmd
} // using conn