Ejemplo n.º 1
0
 /// <summary>
 /// 返回第一行第一列的值
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal object ExecuteScalar(DbCommand cmd)
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         cmd.Connection.Open();
         object ret = cmd.ExecuteScalar();
         cmd.Connection.Close();
         return(ret);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 执行SQL,返回影响行数
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal int ExecuteNonQuery(DbCommand cmd)
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         cmd.Connection.Open();
         int ret = cmd.ExecuteNonQuery();
         cmd.Connection.Close();
         return(ret);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 执行SQL,返回datatable
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal DataTable ExecuteDataTable(DbCommand cmd)
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         DbDataAdapter dbDataAdapter = DbCommandMng.CreateDataAdapter();
         dbDataAdapter.SelectCommand = cmd;
         DataTable dataTable = new DataTable();
         dbDataAdapter.Fill(dataTable);
         return(dataTable);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 执行SQL,返回dataSet
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal DataSet ExecuteDataSet(DbCommand cmd)
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         DbDataAdapter dbDataAdapter = DbCommandMng.CreateDataAdapter();
         dbDataAdapter.SelectCommand = cmd;
         DataSet dataset = new DataSet();
         dbDataAdapter.Fill(dataset);
         return(dataset);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 执行SQL,返回dataSet
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        internal DataSet ExecuteDataSet(DbCommand cmd, Trans trans)
        {
            cmd.Connection  = trans.DbConnection;
            cmd.Transaction = trans.DbTrans;
            DbDataAdapter dbDataAdapter = DbCommandMng.CreateDataAdapter();

            dbDataAdapter.SelectCommand = cmd;
            DataSet dataset = new DataSet();

            dbDataAdapter.Fill(dataset);
            return(dataset);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 返回第一行,并转化成实体
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal T ToSingle <T>(DbCommand cmd) where T : class, new()
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         cmd.Connection.Open();
         using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
         {
             reader.Read();
             var item = FillModel <T>(reader);
             //if (cmd.Connection.State == ConnectionState.Open)
             //    cmd.Connection.Close();
             return(item);
         }
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 查询第一列集合,返回列表
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cmd"></param>
 /// <returns></returns>
 internal List <T> ExecuteScalarList <T>(DbCommand cmd)
 {
     using (cmd.Connection = DbCommandMng.CreateConnection())
     {
         List <T> list = new List <T>();
         cmd.Connection.Open();
         using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
         {
             while (reader.Read())
             {
                 list.Add((reader[0].To <T>()));
             }
             //if(cmd.Connection.State==ConnectionState.Open)
             //    cmd.Connection.Close();
             return(list);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 查询所有集合,返回实体列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cmd"></param>
        /// <returns></returns>
        internal List <T> ToList <T>(DbCommand cmd) where T : class, new()
        {
            List <T> list = new List <T>();

            using (cmd.Connection = DbCommandMng.CreateConnection())
            {
                cmd.Connection.Open();
                using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        list.Add(FillModel <T>(reader));
                    }
                    //if (cmd.Connection.State == ConnectionState.Open)
                    //    cmd.Connection.Close();

                    cmd.Connection.Close();
                }
            }
            return(list);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 事物
 /// mysql表需要设置为alter table userinfo engine=InnoDB;
 /// </summary>
 public Trans()
 {
     conn = DbCommandMng.CreateConnection();
     conn.Open();
     dbTrans = conn.BeginTransaction();
 }
Ejemplo n.º 10
0
 private DbQuery(string sql)
 {
     Command     = DbCommandMng.CreateCommand();
     CommandText = sql;
 }