[C#]分享一个以前的项目使用的DataBaseAccess类(2)

try
                {
                    StreamWriter swDebugOutput = new StreamWriter(strPath + DateTime.Now.ToLongDateString() + ".ini", true, System.Text.Encoding.Unicode);
                    swDebugOutput.Write("time:" + DateTime.Now.ToString() + "\r\n" + objDebugInfo + "\r\n\r\n");
                    swDebugOutput.Close();
                    swDebugOutput.Dispose();
                }
                catch (Exception ex)
                {
                    throw ex;
                }               
            }

#endif
        }

#endregion

#region "***** Database Basic Operation *****"

#region ExecuteSql

/// <summary>
        /// Execute SQL(insert,delete,update)command,return the number of the rows which are affected
        /// </summary>
        /// <param>SQL Command which will be Executed</param>
        /// <returns>return the number of the rows which are affected</returns>       
        public int ExecuteSql(SqlCommand sqlcmd)
        {
            debug("Now Execute DataBaseAccess's Method:ExecuteSql(SqlCommand),Return Type:int ");
            this.conn.Open();
            sqlcmd.Connection = this.conn;
            SqlTransaction trans = this.conn.BeginTransaction();
            sqlcmd.Transaction = trans;
            try
            {               
                debug("Execute SQL Command:" + sqlcmd.CommandText);
                int iReturnValue = sqlcmd.ExecuteNonQuery();
                trans.Commit();
                return iReturnValue;
            }
            catch (SqlException ex)
            {               
                debug("Exception Information:" + ex.ToString());
                trans.Rollback();
                throw ex;
            }
            finally
            {
                sqlcmd.Dispose();
                this.conn.Close();
            }
        }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjwyj.html