當前位置: 首頁>>代碼示例>>C#>>正文


C# NpgsqlTransaction.Rollback方法代碼示例

本文整理匯總了C#中Npgsql.NpgsqlTransaction.Rollback方法的典型用法代碼示例。如果您正苦於以下問題:C# NpgsqlTransaction.Rollback方法的具體用法?C# NpgsqlTransaction.Rollback怎麽用?C# NpgsqlTransaction.Rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Npgsql.NpgsqlTransaction的用法示例。


在下文中一共展示了NpgsqlTransaction.Rollback方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExecuteNonqueryTr

 public int ExecuteNonqueryTr(string sql, out NpgsqlTransaction transaction, params NpgsqlParameter[] parameters)
 {
     transaction = this.Connection.BeginTransaction();
     try
     {
         using(NpgsqlCommand cmd = this.Connection.CreateCommand())
         {
             cmd.CommandText = sql;
             foreach(NpgsqlParameter param in parameters)
                 cmd.Parameters.Add(param);
             return cmd.ExecuteNonQuery();
         }
     }
     catch
     {
         transaction.Rollback();
         throw;
     }
 }
開發者ID:langpavel,項目名稱:LPS-old,代碼行數:19,代碼來源:ConnectionInfo.cs

示例2: getData

 /// <summary>
 /// Lấy dữ liệu từ câu lệnh chứa trong thuộc tính Command
 /// </summary>
 /// <returns></returns>
 private DataSet getData() //Get data with SQLcommand
 {
     Connect();
     trans = conn.BeginTransaction();
     DataSet ds = new DataSet();
     cmd.Connection = conn;
     cmd.CommandText = Command;
     cmd.CommandType = Commandtype;
     cmd.Transaction = trans;
     NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(cmd);
     try
     {
         adapter.Fill(ds);
         trans.Commit();
         Disconnect();
         return ds;
     }
     catch (NpgsqlException ex)
     {
         Error = ex.Message;
         trans.Rollback();
     }
     return null;
 }
開發者ID:Fucmeo,項目名稱:ou-qlns,代碼行數:28,代碼來源:DataProvider.cs

示例3: executeNonQuery

        /// <summary>
        /// Thực Thi các câu lệnh SQL (thường là UPDATE)
        /// </summary>
        /// <returns>giá trị các dòng có ảnh hưởng</returns>
        private int executeNonQuery()// Execute a command without return
        {
            Connect();
            trans = conn.BeginTransaction();
            cmd.CommandText = Command;
            cmd.CommandType = Commandtype;
            cmd.Connection = conn;
            cmd.Transaction = trans;
            int rowEffect = 0;
            try
            {
                rowEffect = cmd.ExecuteNonQuery();

                trans.Commit();
            }
            catch (NpgsqlException ex)
            {
                Error = ex.Message;
                trans.Rollback();
            }
            Disconnect();
            return rowEffect;
        }
開發者ID:Fucmeo,項目名稱:ou-qlns,代碼行數:27,代碼來源:DataProvider.cs

示例4: executeScalar

 /// <summary>
 /// thực thi SQL, thường dùng cho các dòng lệnh MAX,AVG,COUNT,.....
 /// </summary>
 /// <returns>Object</returns>
 private object executeScalar()// Execute a command return only 1 value
 {
     Connect();
     trans = conn.BeginTransaction();
     cmd.CommandText = Command;
     cmd.CommandType = Commandtype;
     cmd.Transaction = trans;
     cmd.Connection = conn;
     object obj = null;
     try
     {
         obj = cmd.ExecuteScalar();
         trans.Commit();
     }
     catch (NpgsqlException ex)
     {
         trans.Rollback();
         if (ex.Code == "23505")
         {
             if(ex.BaseMessage.Contains("quyet_dinh"))
                 throw new Exception("Mã quyết định đã tồn tại, xin vui lòng kiểm tra lại.");
             else if(ex.BaseMessage.Contains("ma_nv"))
                 throw new Exception("Mã nhân viên đã tồn tại, xin vui lòng kiểm tra lại.");
         }
         throw new Exception(ex.Message);
         
     }
     Disconnect();
     return obj;
 }
開發者ID:Fucmeo,項目名稱:ou-qlns,代碼行數:34,代碼來源:DataProvider.cs

示例5: getDataReader

        /// <summary>
        /// Lấy Dữ Liệu Từng Dòng
        /// </summary>
        /// <returns>IDataReader</returns>
        private IDataReader getDataReader() // Đọc dữ liệu dạng Datareader
        {
            Connect();
            trans = conn.BeginTransaction();
            NpgsqlDataReader datard = null;
            try
            {
                cmd.CommandText = Command;
                cmd.CommandType = Commandtype;
                cmd.Transaction = trans;
                datard = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                trans.Commit();
            }
            catch (NpgsqlException ex)
            {
                Error = ex.Message;
                trans.Rollback();

            }
            // Disconnect();
            return datard;
        }
開發者ID:Fucmeo,項目名稱:ou-qlns,代碼行數:26,代碼來源:DataProvider.cs


注:本文中的Npgsql.NpgsqlTransaction.Rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。