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

/// <summary>
        /// Create new SqlComand which has Parameters,Set Stored Procedure Flag
        /// </summary>
        /// <param></param>
        /// <param></param>
        /// <param></param>
        /// <returns></returns>       
        public static SqlCommand CreateCommand(string strSql, SqlParameter[] sqlParameters, bool bIsStoredProcedure)
        {
            SqlCommand sqlcmd = new SqlCommand(strSql);

if (bIsStoredProcedure)
                sqlcmd.CommandType = CommandType.StoredProcedure;
            else
                sqlcmd.CommandType = CommandType.Text;

foreach (SqlParameter param in sqlParameters)
            {
                sqlcmd.Parameters.Add(param);
            }
            return sqlcmd;
        }

/// <summary>
        /// Create new SqlComand which has Parameters,Set Stored Procedure Flag and DataBase Connection
        /// </summary>
        /// <param></param>
        /// <param></param>
        /// <param></param>
        /// <returns></returns>       
        public static SqlCommand CreateCommand(string strSql, SqlParameter[] sqlParameters, bool bIsStoredProcedure, SqlConnection sqlconn)
        {
            SqlCommand sqlcmd = new SqlCommand(strSql, sqlconn);

if (bIsStoredProcedure)
                sqlcmd.CommandType = CommandType.StoredProcedure;
            else
                sqlcmd.CommandType = CommandType.Text;

foreach (SqlParameter param in sqlParameters)
            {
                sqlcmd.Parameters.Add(param);
            }
            return sqlcmd;
        }

/// <summary>
        /// Create new SqlDataAdapter which has Parameters and set DataBase Connection
        /// </summary>
        /// <param></param>
        /// <param></param>
        public static SqlDataAdapter CreateDataAdapter(string strSql, SqlParameter[] sqlParameters, SqlConnection sqlconn)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter(strSql, sqlconn);
            foreach (SqlParameter param in sqlParameters)
            {
                sqlda.SelectCommand.Parameters.Add(param);
            }
            return sqlda;
        }

/// <summary>
        /// Create new SqlDataAdapter which has Parameters,Set Stored Procedure Flag and DataBase Connection
        /// </summary>
        /// <param></param>
        /// <param></param>
        /// <param></param>
        /// <returns></returns>
        public static SqlDataAdapter CreateDataAdapter(string strSql, SqlParameter[] sqlParameters, bool bIsStoredProcedure, SqlConnection sqlconn)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter(strSql, sqlconn);

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

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