Beispiel #1
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;
        }
Beispiel #2
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;
        }
Beispiel #3
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;
        }