Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Transaction in C# On Procedure

How to use Transaction in C# Code On Procedure?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can do something like this using ADO .NET:

    SqlConnection con = new SqlConnection("YOURConnection");
    SqlCommand command = new SqlCommand("your procedure",con);
    con.Open();
    // this is a class you can use in order to manage transaction in C# for MS SQL
    // start scope
    SqlTransaction trans = con.BeginTransaction();
    // set transaction for your command
    command.Transaction = trans;

    try
    {
        // execute your stored procedure or even multiple procedures/commands
        command.ExecuteNonQuery();
        // transaction will be successfully finished
        trans.Commit();
    }
    catch (Exception)
    {
        // if any errors you need to rollback it
        trans.Rollback();
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading