Results 1 to 2 of 2

Thread: [2.0] How to commit

Threaded View

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Question [2.0] How to commit

    Hi all
    I make a function for execute multile query I am using transaction commit and rollback in it!
    but the problem is how to commit the transaction it showing me error that use of unsigned variable transaction!


    C# Code:
    1. public bool ExecuteMultipleQuery(string[] queryString)
    2.         {
    3.             SqlConnection myConnection;
    4.             System.Data.SqlClient.SqlTransaction transaction;
    5.             DbCommand dbCommand;
    6.             myConnection = OpenNewConnection();//OPEN THE CONNECTION
    7.             dbCommand = myConnection.CreateCommand();
    8.             try
    9.             {
    10.                 transaction = myConnection.BeginTransaction();
    11.                 dbCommand.CommandType = CommandType.Text;
    12.                 dbCommand.Transaction = transaction;
    13.                 dbCommand.Connection = myConnection;
    14.                 foreach (string query in queryString)
    15.                 {
    16.                     dbCommand.CommandText = query;
    17.                     dbCommand.ExecuteNonQuery();
    18.                 }
    19.                 transaction.Rollback();
    20.                 return true;
    21.             }
    22.             catch (Exception ex)
    23.             {
    24.                 transaction.Commit();//HERE GIVING ME ERROR USE OF UNSIGNED
    25.                 //VARIABLE  transaction
    26.                 return false;
    27.             }
    28.             finally
    29.             {
    30.                 myConnection.Close();
    31.                 dbCommand.Dispose();
    32.             }
    33.         }
    Last edited by shakti5385; Aug 14th, 2007 at 06:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width