예제 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SP.Model.article model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update article set ");
            strSql.Append("total1=total1+1");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@aid", SqlDbType.Int, 4)
            };

            parameters[0].Value = model.aid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SP.Model.article model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into article(");
            strSql.Append("title,memo,total1,lname,atime)");
            strSql.Append(" values (");
            strSql.Append("@title,@memo,@total1,@lname,@atime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",  SqlDbType.VarChar, 100),
                new SqlParameter("@memo",   SqlDbType.NText),
                new SqlParameter("@total1", SqlDbType.Int,       4),
                new SqlParameter("@lname",  SqlDbType.VarChar,  20),
                new SqlParameter("@atime",  SqlDbType.DateTime)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.memo;
            parameters[2].Value = model.total1;
            parameters[3].Value = model.lname;
            parameters[4].Value = model.atime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public SP.Model.article DataRowToModel(DataRow row)
 {
     SP.Model.article model = new SP.Model.article();
     if (row != null)
     {
         if (row["aid"] != null && row["aid"].ToString() != "")
         {
             model.aid = int.Parse(row["aid"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["memo"] != null)
         {
             model.memo = row["memo"].ToString();
         }
         if (row["total1"] != null && row["total1"].ToString() != "")
         {
             model.total1 = int.Parse(row["total1"].ToString());
         }
         if (row["lname"] != null)
         {
             model.lname = row["lname"].ToString();
         }
         if (row["atime"] != null && row["atime"].ToString() != "")
         {
             model.atime = DateTime.Parse(row["atime"].ToString());
         }
     }
     return(model);
 }
예제 #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SP.Model.article model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update article set ");
            strSql.Append("title=@title,");
            strSql.Append("memo=@memo,");
            strSql.Append("total1=@total1,");
            strSql.Append("lname=@lname,");
            strSql.Append("atime=@atime");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",  SqlDbType.VarChar,   100),
                new SqlParameter("@memo",   SqlDbType.NText),
                new SqlParameter("@total1", SqlDbType.Int,         4),
                new SqlParameter("@lname",  SqlDbType.VarChar,    20),
                new SqlParameter("@atime",  SqlDbType.DateTime),
                new SqlParameter("@aid",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.memo;
            parameters[2].Value = model.total1;
            parameters[3].Value = model.lname;
            parameters[4].Value = model.atime;
            parameters[5].Value = model.aid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SP.Model.article GetModel(int aid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 aid,title,memo,total1,lname,pic,atime from article ");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@aid", SqlDbType.Int, 4)
            };
            parameters[0].Value = aid;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }