搜尋此網誌
2011年8月10日 星期三
ASP.NET Oracel 資料庫的連結應用(新增修改刪除)
//無Transaction
int irow = 0;
//連線資訊
OracleConnection cn = new
OracleConnection(System.Configuration.ConfigurationManager.AppSettings["XXXX"]);
OracleCommand Cmd = new OracleCommand();
Cmd.CommandText = SQL;
Cmd.Connection = cn;
cn.Open();
try
{
irow = Cmd.ExecuteNonQuery();
cn.Close();
if (irow != -1)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
cn.Close();
return false;
}
//Transaction
int irow = 0;
OracleConnection cn = new OracleConnection(System.Configuration.ConfigurationManager.AppSettings["XXX"]);
OracleCommand Cmd = new OracleCommand();
OracleTransaction objTransaction;
cn.Open();
Cmd.Connection = cn;
objTransaction = cn.BeginTransaction(IsolationLevel.ReadCommitted);
Cmd.Transaction = objTransaction;
try
{
Cmd.CommandText = SQL;
irow = Cmd.ExecuteNonQuery();
objTransaction.Commit();
cn.Close();
if (irow != -1)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
objTransaction.Rollback();
cn.Close();
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言