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

if (bIsStoredProcedure)
                sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            else
                sqlda.SelectCommand.CommandType = CommandType.Text;

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

/// <summary>
        /// Create SqlParameter[]
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static SqlParameter[] CreateSqlParameters(object[,] sqlParameterArr)
        {
            SqlParameter[] sqlParameters = new SqlParameter[sqlParameterArr.GetLength(0)];
            int i = 0;
            foreach (SqlParameter param in sqlParameters)
            {
                sqlParameters[i] = new SqlParameter(Convert.ToString(sqlParameterArr[i, 0]), sqlParameterArr[i, 1]);
                i++;
            }
            return sqlParameters;
        }

/// <summary>
        /// add Parameters for Command
        /// </summary>
        /// <param></param>
        /// <param></param>
        public static void AddCommandParams(ref SqlCommand sqlcmd, SqlParameter[] sqlParameters)
        {
            foreach (SqlParameter param in sqlParameters)
            {
                sqlcmd.Parameters.Add(param);
            }
        }

/// <summary>
        /// add Parameters for DataAdapter
        /// </summary>
        /// <param></param>
        /// <param></param>
        public static void AddDataAdapterParam(ref SqlDataAdapter sqlda, SqlParameter[] sqlParameters)
        {
            foreach (SqlParameter param in sqlParameters)
            {
                sqlda.SelectCommand.Parameters.Add(param);
            }
        }

/// <summary>
        /// Get SQLScript
        /// </summary>
        /// <param></param>
        /// <param></param>
        public static string GetSQLScript(string strFilepath,string strNodePath)
        {
            string strSql;
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(strFilepath);
            XmlNode node = xmldoc.SelectSingleNode(strNodePath);
            strSql = node.ChildNodes[0].InnerText;
            return strSql;
        }              
    }
    #endregion
}

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

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