the use of a transaction
using System;
using System.Data;
using System.Data.SqlClient;
class ExecuteTransaction {
public static void Main() {
SqlConnection mySqlConnection = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=sa");
mySqlConnection.Open();
SqlTransaction mySqlTransaction = mySqlConnection.BeginTransaction();
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.Transaction = mySqlTransaction;
mySqlCommand.CommandText =
"INSERT INTO Customers (" +
" CustomerID, CompanyName" +
") VALUES (" +
" 'J3COM', 'Jason Price Corporation'" +
")";
mySqlCommand.ExecuteNonQuery();
mySqlCommand.CommandText =
"INSERT INTO Orders (" +
" CustomerID" +
") VALUES (" +
" 'J3COM'" +
")";
mySqlCommand.ExecuteNonQuery();
mySqlTransaction.Commit();
mySqlConnection.Close();
}
}
|
HTML code for linking to this page:
Related in same category :
-
|