C# sybase資料庫交易的寫法如下:
using Sybase.Data.AseClient;
AseConnection aseCon;
AseCommand dcom;
aseCon = new AseConnection("DataSource=127.0.0.1;Port=5000;Database=資料庫;UID=帳號;PWD=密碼;charset=utf8");
aseCon.Open();
//開啟資料庫交易
AseTransaction aseTransaction = aseCon.BeginTransaction();
dcom = new AseCommand();
dcom.Connection = aseCon;
dcom.Transaction = aseTransaction;
try
{
//insert bank
dcom.CommandText = "INSERT INTO bank1 VALUES('5555555', 0)";
dcom.ExecuteNonQuery();
dcom.CommandText = "INSERT INTO bank2 VALUES('5555555', 0)";
dcom.ExecuteNonQuery();
//執行成功時Commit
aseTransaction.Commit();
}
catch (Exception err)
{
//執行失敗時Rollback
aseTransaction.Rollback();
MessageBox.Show(err.Message);
}
aseCon.Close();
沒有留言:
張貼留言