Ejemplo n.º 1
0
        /// <summary>取一个字段的值
        ///
        /// </summary>
        /// <param name="filed">字段,如sum(je)</param>
        /// <param name="cond">条件,如userid=2</param>
        /// <returns></returns>
        public string GetOneFiled(string filed, string cond)
        {
            string sql = "select " + filed + " from [user]";

            if (!string.IsNullOrEmpty(cond))
            {
                sql += " where " + cond;
            }
            MSSQLHelper h = new MSSQLHelper();

            h.CreateCommand(sql);
            return(h.ExecuteScalar());
        }
Ejemplo n.º 2
0
        /// <summary>计算记录数
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public int CalcCount(string cond, IDbDataParameter[] paras = null)
        {
            string sql = "select count(1) from [user]";

            if (!string.IsNullOrEmpty(cond))
            {
                sql += " where " + cond;
            }
            MSSQLHelper h = new MSSQLHelper();

            h.CreateCommand(sql);
            if (paras != null)
            {
                h.AddParameter(paras);
            }
            return(int.Parse(h.ExecuteScalar()));
        }
Ejemplo n.º 3
0
        /// <summary>增加一条数据
        ///
        /// </summary>
        public int Add(mhqNetAPP.Model.User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [user](");
            strSql.Append("[creatdate], [username], [password], [face], [usertype], [phone], [qq], [email], [remark]  )");
            strSql.Append(" values (");
            strSql.Append("@creatdate, @username, @password, @face, @usertype, @phone, @qq, @email, @remark  )");
            strSql.Append(";select @@IDENTITY");
            MSSQLHelper h = new MSSQLHelper();

            h.CreateCommand(strSql.ToString());
            if (model.creatdate == null)
            {
                h.AddParameter("@creatdate", DBNull.Value);
            }
            else
            {
                h.AddParameter("@creatdate", model.creatdate);
            }
            if (model.username == null)
            {
                h.AddParameter("@username", DBNull.Value);
            }
            else
            {
                h.AddParameter("@username", model.username);
            }
            if (model.password == null)
            {
                h.AddParameter("@password", DBNull.Value);
            }
            else
            {
                h.AddParameter("@password", model.password);
            }
            if (model.face == null)
            {
                h.AddParameter("@face", DBNull.Value);
            }
            else
            {
                h.AddParameter("@face", model.face);
            }
            if (model.usertype == null)
            {
                h.AddParameter("@usertype", DBNull.Value);
            }
            else
            {
                h.AddParameter("@usertype", model.usertype);
            }
            if (model.phone == null)
            {
                h.AddParameter("@phone", DBNull.Value);
            }
            else
            {
                h.AddParameter("@phone", model.phone);
            }
            if (model.qq == null)
            {
                h.AddParameter("@qq", DBNull.Value);
            }
            else
            {
                h.AddParameter("@qq", model.qq);
            }
            if (model.email == null)
            {
                h.AddParameter("@email", DBNull.Value);
            }
            else
            {
                h.AddParameter("@email", model.email);
            }
            if (model.remark == null)
            {
                h.AddParameter("@remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@remark", model.remark);
            }

            int    result;
            string obj = h.ExecuteScalar();

            if (!int.TryParse(obj, out result))
            {
                return(0);
            }
            return(result);
        }