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

if (myDr.Read())
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            catch (SqlException ex)
            {
                debug("Exception Information:" + ex.ToString());
                throw ex;
            }
            finally
            {
                sqlcmd.Dispose();
                this.conn.Close();
            }
        }

/// <summary>
        /// Execute SQL command,if result set has note return 1,if result set is null return 0
        /// </summary>
        /// <param>SQL Command which will be Executed</param>
        /// <returns>Execute SQL command,if result set has note return 1,if result set is null return 0</returns>       
        public int ExecScalarEx(string strSql)
        {
            debug("Now Execute DataBaseAccess's Method:ExecScalarEx(strSql),Return Type:int ");
            return ExecScalarEx(new SqlCommand(strSql, this.conn));
        }

/// <summary>
        /// Execute SQL command,if result set has note return 1,if result set is null return 0
        /// </summary>
        /// <param>SQL Command which will be Executed</param>
        /// <param>SQL Command Collection</param>
        /// <returns>Execute SQL command,if result set has note return 1,if result set is null return 0</returns>       
        public int ExecScalarEx(string strSql, SqlParameter[] sqlParameters)
        {
            debug("Now Execute DataBaseAccess's Method:ExecScalarEx(string,SqlParameter[]),Return Type:int ");
            return ExecScalarEx(SQLHelper.CreateCommand(strSql, sqlParameters, this.conn));
        }

#endregion

#region ExecuteSqlDs

/// <summary>
        /// Execute SQL Command,return DataSet.
        /// </summary>
        /// <param>SQL Command which will be Executed</param>
        /// <param>table name</param>
        /// <returns>return DataSet.</returns>
        public DataSet ExecuteSqlDs(SqlCommand sqlcmd, string strTableName)
        {
            debug("Now Execute DataBaseAccess's Method:ExecuteSqlDs(SqlCommand,string),Return Type:DataSet ");
            sqlcmd.Connection = this.conn;
            SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
            DataSet dsReturn = new DataSet();
            try
            {
                debug("Execute SQL Command:" + sqlcmd.CommandText);
                this.conn.Open();
                sqlda.Fill(dsReturn, strTableName);
                return dsReturn;          
            }
            catch (SqlException ex)
            {
                debug("Exception information:" + ex.ToString());
                throw ex;
            }
            finally
            {
                sqlcmd.Dispose();
                sqlda.Dispose();
                this.conn.Close();
            }
        }
       
        /// <summary>
        /// Execute SQL Command,return DataSet.
        /// </summary>
        /// <param>SQL Command which will be Executed</param>
        /// <param>table name</param>
        /// <returns>return dataset.</returns>
        public DataSet ExecuteSqlDs(string strSql, string strTableName)
        {
            debug("Now Execute DataBaseAccess's Method:ExecuteSqlDs(string,string),Return Type:DataSet ");
            return ExecuteSqlDs(new SqlCommand(strSql, this.conn), strTableName);
        }       

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

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