示例#1
0
        /// <summary>
        /// 统计
        /// </summary>
        public static int Count(string table, string where, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            int row = Convert.ToInt32(db.ExecuteScalar(DBSql.Count(table, where)).ToString());
            db.Dispose();

            return row;
        }
示例#2
0
        /// <summary>
        /// 删除
        /// </summary>
        public static int Delete(string table, string where, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            int row = db.ExecuteNonQuery(DBSql.Delete(table, where));
            db.Dispose();

            return row;
        }
示例#3
0
        /// <summary>
        /// 添加
        /// </summary>
        public static int Insert(string table, Dictionary<string, object> field)
        {
            DBHelper db = new DBHelper();
            StringBuilder sql = new StringBuilder();

            string key = String.Empty;
            string value = String.Empty;
            foreach (KeyValuePair<string, object> s in field)
            {
                key += String.Format("[{0}],", s.Key);
                value += String.Format("@{0},", s.Key);
                db.ParameterAdd("@" + s.Key, s.Value);
            }
            sql.AppendFormat("insert into [{0}](", table);
            sql.Append(key.TrimEnd(','));
            sql.Append(")values(");
            sql.Append(value.TrimEnd(','));
            sql.Append(")");

            int row = db.ExecuteNonQuery(sql.ToString());
            db.Dispose();

            return row;
        }
示例#4
0
        /// <summary>
        /// 更新
        /// </summary>
        public static int Update(string table, Dictionary<string, object> field, string where, List<string> list = null)
        {
            DBHelper db = new DBHelper();
            StringBuilder sql = new StringBuilder();

            sql.AppendFormat("update [{0}] set ", table);
            foreach (KeyValuePair<string, object> s in field)
            {
                sql.AppendFormat("[{0}]=@{0},", s.Key);
                db.ParameterAdd("@" + s.Key, s.Value);
            }
            sql.Remove(sql.Length - 1, 1);
            if (where != "")
            {
                sql.AppendFormat(" where {0}", where);
            }

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            int row = db.ExecuteNonQuery(sql.ToString());
            db.Dispose();

            return row;
        }
示例#5
0
        /// <summary>
        /// 筛选
        /// </summary>
        public static dynamic SqlReader(string sql, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            dynamic dy = db.ExecuteReader(sql);
            db.Dispose();

            return dy;
        }
示例#6
0
        /// <summary>
        /// 筛选
        /// </summary>
        public static DataSet Sql(string sql, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            DataSet ds = db.ExecuteDataSet(sql);
            db.Dispose();

            return ds;
        }
示例#7
0
        /// <summary>
        /// 筛选
        /// </summary>
        public static DataSet Select(string table, int top, string field, string where, string order, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            DataSet ds = db.ExecuteDataSet(DBSql.Select(table, top, field, where, order));
            db.Dispose();

            return ds;
        }
示例#8
0
        /// <summary>
        /// 单行数据
        /// </summary>
        public static string Row(string table, string field, string where, List<string> list = null)
        {
            DBHelper db = new DBHelper();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    db.ParameterAdd("@" + i, list[i]);
                }
            }

            string row = db.ExecuteScalar(DBSql.Select(table, 1, field, where, String.Empty)).ToString();
            db.Dispose();

            return row;
        }