Answers for ".net core executenonqueryasync transaction"

C#
0

.net core executenonqueryasync transaction

var sqlQuery = "delete from table";
    using (var connection = new SqlConnection(ConnectionString))
    {
        await connection.OpenAsync();
        using (var tran = connection.BeginTransaction())
        using (var command = new SqlCommand(sqlQuery, connection, tran))
        {
            try {
                await command.ExecuteNonQueryAsync();
            } catch {
                tran.Rollback();
                throw;
            }
            tran.Commit();
        }
    }
Posted by: Guest on June-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language