public static DataTable ExcuteTable(string sqlstr)
        {
            MyCatConnection conn = null;

            try
            {
                conn = OpenConn();
                var cmd = conn.CreateCommand();
                cmd.CommandTimeout = 0;
                cmd.CommandText    = sqlstr;
                cmd.CommandType    = CommandType.Text;
                MyCatDataAdapter da = new MyCatDataAdapter();
                da.SelectCommand = cmd;
                var reader = cmd.ExecuteReader();
                CloseConn(conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return(dt);
            }
            catch (Exception ex)
            {
                //  Console.WriteLine(ex.Message);
                DataTable dt = new DataTable();
                return(dt);
            }
            finally
            {
                CloseConn(conn);
            }
        }
        public static DataTable ExcuteTable(string sqlstr, MyCatParameter[] parameters)
        {
            MyCatConnection conn = null;

            try
            {
                conn = OpenConn();
                var cmd = conn.CreateCommand();
                cmd.CommandTimeout = 0;
                cmd.CommandText    = sqlstr;
                cmd.CommandType    = CommandType.Text;
                cmd.Parameters.AddRange(parameters);
                MyCatDataAdapter da = new MyCatDataAdapter();
                da.SelectCommand = cmd;
                var reader = cmd.ExecuteReader();
                // int execute = cmd.ExecuteNonQuery();
                CloseConn(conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return(dt);
            }
            catch (Exception ex)
            {
                DataTable dt = new DataTable();
                return(dt);
            }
            finally
            {
                CloseConn(conn);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public static DataSet Query(string SQLString)
 {
     using (MyCatConnection connection = new MyCatConnection(ConfigurationManager.AppSettings["PersonCenterConnectionString"]))
     {
         DataSet ds = new DataSet();
         connection.Open();
         MyCatDataAdapter command = new MyCatDataAdapter(SQLString, connection);
         command.Fill(ds);
         connection.Close();
         return(ds);
     }
 }
        public static DataTable ExcuteTable(string sqlstr)
        {
            MyCatConnection conn = null;

            try
            {
                /*
                 * cmd.CommandTimeout = 180;
                 *
                 * cmd.CommandText = sql;
                 * DataSet dataset = new DataSet();
                 * SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                 * adapter.Fill(dataset);
                 * return dataset.Tables[0];
                 */



                conn = OpenConn();
                var cmd = conn.CreateCommand();
                cmd.CommandTimeout = 180;
                cmd.CommandText    = sqlstr;
                cmd.CommandType    = CommandType.Text;
                DataSet          dataset = new DataSet();
                MyCatDataAdapter da      = new MyCatDataAdapter();
                da.SelectCommand = cmd;
                // var reader = cmd.ExecuteReader();
                //   DataTable dt = new DataTable();
                //  da.Fill(dt);
                //  CloseConn(conn);
                da.Fill(dataset);
                return(dataset.Tables[0]);
                //   return dt;
            }
            catch (Exception ex)
            {
                //  Console.WriteLine(ex.Message);
                DataTable dt = new DataTable();
                return(dt);
            }
            finally
            {
                CloseConn(conn);
            }
        }