示例#1
0
        public static List <String> ExecSqlReturnItem(String sql, String item)   //返回查找结果集中的某个字段的值,以list形式返回
        {
            MySqlConnection conn    = DatabaseTool.GetSqlConnection();
            MySqlCommand    command = new MySqlCommand(sql, conn);
            MySqlDataReader reader  = command.ExecuteReader();
            List <String>   lst     = new List <string>();

            while (reader.Read())
            {
                lst.Add(reader[item].ToString());
            }
            conn.Close();
            reader.Close();
            return(lst);
        }
示例#2
0
        public static bool ExecSql(String sql)
        {
            MySqlConnection conn    = DatabaseTool.GetSqlConnection();
            MySqlCommand    command = new MySqlCommand(sql, conn);

            if (command.ExecuteNonQuery() > 0)
            {
                conn.Close();
                return(true);
            }
            else
            {
                conn.Close();
                return(false);
            }
        }
示例#3
0
        public static bool ExcelSelectResult(String sql)    //查询到返回true,查询不到返回false
        {
            MySqlConnection  conn = DatabaseTool.GetSqlConnection();
            MySqlDataAdapter da   = new MySqlDataAdapter(sql, conn);
            DataSet          ds   = new DataSet();

            da.Fill(ds);
            if (ds.Tables[0].Rows.Count == 0)
            {
                conn.Close();
                return(false);
            }

            else
            {
                conn.Close();
                return(true);
            }
        }
示例#4
0
        public static List <Dictionary <String, Object> > ExecSqlReturn(String sql) //返回查找结果集的
        {
            List <Dictionary <String, Object> > list = new List <Dictionary <String, Object> >();
            MySqlConnection conn    = DatabaseTool.GetSqlConnection();
            MySqlCommand    command = new MySqlCommand(sql, conn);
            MySqlDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                Dictionary <string, Object> keyValues = new Dictionary <string, Object>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    keyValues.Add(reader.GetName(i), reader.GetFieldValue <Object>(i));
                }
                list.Add(keyValues);
            }
            reader.Close();
            conn.Close();
            return(list);
        }