private void button1_click(object sender, system.eventargs e)
{
sqlconnection conn = new sqlconnection("data source=192.168.2.200;uid=sa; password=;database = haierhr");
conn.open();
/启用事务
sqltransaction tran = conn.begintransaction();
sqlcommand cmd = new sqlcommand();
cmd.connection = conn;
cmd.transaction = tran;
try
{
cmd.commandtext = "update hrrollmain set totalmember=totalmember-100 where rollid = '2005070101'";
cmd.executenonquery();
cmd.commandtext = "update hrrollsum set totalsummember=totalsummember+100 where rollsumid = '20050701'";
cmd.executenonquery();
tran.commit();
messagebox.show("事务提交成功!");
}
catch(exception ex)
{
tran.rollback();
messagebox.show("error!"+ex.message);
}
}
try{
OleDbConnection myConnection = new OleDbConnection(connStr);
myConnection.Open();
OleDbTransaction myTrans = myConnection.BeginTransaction();
//用事务执行,保证数据提交成功
OleDbCommand myCommand = new OleDbCommand();
myCommand.Connection = myConnection;
myCommand.Transaction = myTrans ;
//删除原有此流程的相关人员配置情况
sql_del = "delete from case_workflow_tasklist where proc_id=" + procid + "";
myCommand.CommandText = sql_del;
myCommand.ExecuteNonQuery();
//删除原有此流程的相关线配置情况
sql_del = "delete from case_workflow_transition where proc_id=" + procid + "";
myCommand.CommandText = sql_del;
myCommand.ExecuteNonQuery();
myTrans.Commit();
}
catch(Exception Trans_error)
{
string strErr = Trans_error.Message ;
myTrans.Rollback();
Response.Write(strErr);
return;
}
finally
{
myConnection.Close();
}
public void CreateMyOleDbCommand()
{
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB");
myConnection.Open();
OleDbTransaction myTrans = myConnection.BeginTransaction();
string mySelectQuery = "SELECT * FROM Categories ORDER BY CategoryID";
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection,myTrans);
myCommand.CommandTimeout = 20;
}
-----------------------------