示例#1
0
        /// <summary>
        /// 函数输入SQL语句,输出一个结果集(DATATABLE)
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <returns>返回 DataTable</returns>
        public static DataTable GetTable(string strSql)
        {
            DataTable       dt = new DataTable();
            MySqlConnection cn = DBMySQLHelper.GetCon();

            try
            {
                cn.Open();
                MySqlCommand     cm = new MySqlCommand(strSql, cn);
                MySqlDataAdapter da = new MySqlDataAdapter(cm);
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(DBMySQLHelper), ex, "函数输入SQL语句,输出一个结果集(DATATABLE)", "GetTable", false);
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(dt);
        }
示例#2
0
        /// <summary>
        /// 函数输入SQL语句,返回一个SQLiteDataReader结果集
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <returns>返回 SQLiteDataReader 实例</returns>
        public static MySqlDataReader ExReader(string strSql)
        {
            MySqlConnection cn = DBMySQLHelper.GetCon();
            MySqlDataReader dr = null;

            try
            {
                cn.Open();
                MySqlCommand cm = new MySqlCommand(strSql, cn);
                dr = cm.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(DBMySQLHelper), ex, "函数输入SQL语句,返回一个OleDbDataReader结果集", "MySqlDataReader", false);
            }

            return(dr);
        }
示例#3
0
        /// <summary>
        /// 执行数据库操作语句
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <returns>返回影响行数</returns>
        public static int ExecuteSql(string strSql)
        {
            int             iNum = -1;
            MySqlConnection cn   = DBMySQLHelper.GetCon();
            MySqlCommand    cm   = new MySqlCommand(strSql, cn);

            try
            {
                cn.Open();
                iNum = cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(DBMySQLHelper), ex, "执行数据库操作语句", "ExecuteSql", false);
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(iNum);
        }