「SqlTransaction クラス」の編集履歴(バックアップ)一覧はこちら

SqlTransaction クラス - (2008/04/18 (金) 12:55:19) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

// 現在のページ名 *&this_page()  **概要 .NET Framework で、トランザクション処理を行う方法のひとつ。 これ以外に、TSQL内でBEGIN TRANSACTION ***参照 -[[.NET Framework クラス ライブラリ SqlTransaction クラス>>http://msdn2.microsoft.com/ja-jp/library/system.data.sqlclient.sqltransaction(VS.80).aspx]] ***参考 -[[@IT:.NETエンタープライズWebアプリケーション開発技術大全 接続型データアクセスと短時間トランザクション>>http://www.atmarkit.co.jp/fdotnet/entwebapp/entwebapp10/entwebapp10_01.html]] ***元ネタ -[[トランザクションの実行 - tony-xの備忘録>>http://d.hatena.ne.jp/tony-x/20080214/p3]] **前提条件 -[[新しいプロジェクトの作成]] **手順 以下のソースは、元ネタのURLから転載。 ※ASP.NETではない(Console.WriteLine()とか。)がトランザクションの使い方としては同じ。 #highlight(csharp){{ using (SqlConnection connection = new SqlConnection(connectString)) { connection.Open(); // トランザクション開始 SqlTransaction sqlTran = connection.BeginTransaction(); // SqlCommand クラスにトランザクションを設定 SqlCommand command = connection.CreateCommand(); command.Transaction = sqlTran; try { command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong size')"; command.ExecuteNonQuery(); command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong color')"; command.ExecuteNonQuery(); // コミット sqlTran.Commit(); Console.WriteLine("Both records were written to database."); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Neither record was written to database."); // ロールバック sqlTran.Rollback(); } } }}
// 現在のページ名 *&this_page()  **概要 .NET Framework で、トランザクション処理を行う方法のひとつ。 C#でトランザクションを行うには、これ以外に、 -TSQL内で BEGIN TRANSACTION~ によるデータベーストランザクション。 -@Pageディレクティブで、Transaction属性によるトランザクション。 がある。 ***参照 -[[.NET Framework クラス ライブラリ SqlTransaction クラス>>http://msdn2.microsoft.com/ja-jp/library/system.data.sqlclient.sqltransaction(VS.80).aspx]] ***参考 -[[@IT:.NETエンタープライズWebアプリケーション開発技術大全 接続型データアクセスと短時間トランザクション>>http://www.atmarkit.co.jp/fdotnet/entwebapp/entwebapp10/entwebapp10_01.html]] ***元ネタ -[[トランザクションの実行 - tony-xの備忘録>>http://d.hatena.ne.jp/tony-x/20080214/p3]] **前提条件 -[[新しいプロジェクトの作成]] **手順 以下のソースは、元ネタのURLから転載。 ※ASP.NETではない(Console.WriteLine()とか。)がトランザクションの使い方としては同じ。 #highlight(csharp){{ using (SqlConnection connection = new SqlConnection(connectString)) { connection.Open(); // トランザクション開始 SqlTransaction sqlTran = connection.BeginTransaction(); // SqlCommand クラスにトランザクションを設定 SqlCommand command = connection.CreateCommand(); command.Transaction = sqlTran; try { command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong size')"; command.ExecuteNonQuery(); command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong color')"; command.ExecuteNonQuery(); // コミット sqlTran.Commit(); Console.WriteLine("Both records were written to database."); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Neither record was written to database."); // ロールバック sqlTran.Rollback(); } } }}

表示オプション

横に並べて表示:
変化行の前後のみ表示:
記事メニュー
ウィキ募集バナー