Free Jobs
Reference




Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How to create transaction in datalayer ASP NET c sharp application

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: dhiraj5079 Post Date: 03 Jan 2012 01:52

Introduction:
How to create transaction in datalayer ASP NET C# application



Main Content:
Below code uses Transaction in c#



Public Collection<TestObject> GetTestData(sampleInput)

{

  string testQuery = GetTestQuery(sampleInput);

  DataSet testDataSet = new DataSet();

  string connectionString = GetConnStringFromConfig();

   using(OleDbConnection connection = new OleDbConnection(connectionString))

   {

     try

     {

      OleDbParameters[] parameters = null;

      List<OleDbParameters> parametersList = GetParameterList(sampleInput);

       OleDbTransaction transaction = connection.BeginTransaction();

        if(parametersList != null && parametersList.Count >0)

        {

            parameters = parametersList.ToArray();

            DB2Helper.ExecuteNonQuery(connectionString,CommandType.Text,testQuery,testDataSet,null,parameters);

            DB2Helper.ExecuteNonQuery(connectionString,CommandType.Text,testQuery,testDataSet,null,parameters);

            transaction.Commit();

        }

        else

        {

         DB2Helper.FillDataSet(connectionString,CommandType.Text,testQuery,testDataSet,null,null);

        }

        Datatable testDataTable = testDataSet.Table[0];

     }

     catch(OleDbException ex)

     {

       EnterprizeLogging.Logger.Logerror(ex,ModuleName);

       transaction.RollBack();

     }

   }

}

Conclusion:
Thus we can create transaction in c#



About Writer:
Hi,I am IT Professional From Mumbai


Writer's Link: http://

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)