Exemple #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DTcms.Model.Unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Unit set ");

            strSql.Append(" Name = @Name , ");
            strSql.Append(" Remark = @Remark  ");
            strSql.Append(" where Id=@Id  ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",     SqlDbType.Int,       4),
                new SqlParameter("@Name",   SqlDbType.VarChar, 254),
                new SqlParameter("@Remark", SqlDbType.VarChar, 254)
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.Remark;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DTcms.Model.Unit GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, Name, Remark  ");
            strSql.Append("  from Unit ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;


            DTcms.Model.Unit model = new DTcms.Model.Unit();
            DataSet          ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Name   = ds.Tables[0].Rows[0]["Name"].ToString();
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(DTcms.Model.Unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Unit(");
            strSql.Append("Name,Remark");
            strSql.Append(") values (");
            strSql.Append("@Name,@Remark");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",   SqlDbType.VarChar, 254),
                new SqlParameter("@Remark", SqlDbType.VarChar, 254)
            };


            parameters[0].Value = model.Name;
            parameters[1].Value = model.Remark;
            return(DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0);
        }