示例#1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(MyBlogs.Model.Blogcommentarticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into blogcommentarticle(");
            strSql.Append("ArticleId,AuthorId,CommentTitle,CommentContent,AddTime,IsDel)");
            strSql.Append(" values (");
            strSql.Append("@ArticleId,@AuthorId,@CommentTitle,@CommentContent,@AddTime,@IsDel)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@ArticleId",      MySqlDbType.Int32,      11),
                new MySqlParameter("@AuthorId",       MySqlDbType.Int32,      11),
                new MySqlParameter("@CommentTitle",   MySqlDbType.VarChar,    50),
                new MySqlParameter("@CommentContent", MySqlDbType.Text),
                new MySqlParameter("@AddTime",        MySqlDbType.Timestamp),
                new MySqlParameter("@IsDel",          MySqlDbType.Bit)
            };
            parameters[0].Value = model.ArticleId;
            parameters[1].Value = model.AuthorId;
            parameters[2].Value = model.CommentTitle;
            parameters[3].Value = model.CommentContent;
            parameters[4].Value = model.AddTime;
            parameters[5].Value = model.IsDel;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public MyBlogs.Model.Blogcommentarticle DataRowToModel(DataRow row)
 {
     MyBlogs.Model.Blogcommentarticle model = new MyBlogs.Model.Blogcommentarticle();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["ArticleId"] != null && row["ArticleId"].ToString() != "")
         {
             model.ArticleId = int.Parse(row["ArticleId"].ToString());
         }
         if (row["AuthorId"] != null && row["AuthorId"].ToString() != "")
         {
             model.AuthorId = int.Parse(row["AuthorId"].ToString());
         }
         if (row["CommentTitle"] != null)
         {
             model.CommentTitle = row["CommentTitle"].ToString();
         }
         if (row["CommentContent"] != null)
         {
             model.CommentContent = row["CommentContent"].ToString();
         }
         if (row["AddTime"] != null && row["AddTime"].ToString() != "")
         {
             model.AddTime = DateTime.Parse(row["AddTime"].ToString());
         }
         if (row["IsDel"] != null && row["IsDel"].ToString() != "")
         {
             if ((row["IsDel"].ToString() == "1") || (row["IsDel"].ToString().ToLower() == "true"))
             {
                 model.IsDel = true;
             }
             else
             {
                 model.IsDel = false;
             }
         }
     }
     return(model);
 }
示例#3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(MyBlogs.Model.Blogcommentarticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update blogcommentarticle set ");
            strSql.Append("ArticleId=@ArticleId,");
            strSql.Append("AuthorId=@AuthorId,");
            strSql.Append("CommentTitle=@CommentTitle,");
            strSql.Append("CommentContent=@CommentContent,");
            strSql.Append("IsDel=@IsDel");
            strSql.Append(" where Id=@Id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@ArticleId",      MySqlDbType.Int32,   11),
                new MySqlParameter("@AuthorId",       MySqlDbType.Int32,   11),
                new MySqlParameter("@CommentTitle",   MySqlDbType.VarChar, 50),
                new MySqlParameter("@CommentContent", MySqlDbType.Text),
                new MySqlParameter("@IsDel",          MySqlDbType.Bit),
                new MySqlParameter("@Id",             MySqlDbType.Int32, 11)
            };
            parameters[0].Value = model.ArticleId;
            parameters[1].Value = model.AuthorId;
            parameters[2].Value = model.CommentTitle;
            parameters[3].Value = model.CommentContent;
            parameters[4].Value = model.IsDel;
            parameters[5].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MyBlogs.Model.Blogcommentarticle GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id,ArticleId,AuthorId,CommentTitle,CommentContent,AddTime,IsDel from blogcommentarticle ");
            strSql.Append(" where Id=@Id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Id", MySqlDbType.Int32)
            };
            parameters[0].Value = Id;

            MyBlogs.Model.Blogcommentarticle model = new MyBlogs.Model.Blogcommentarticle();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);

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