Example #1
0
        public List <PostUpdate> GetUpdatePosts()
        {
            List <PostUpdate> updateposts = new List <PostUpdate>();

            using (MySqlCommand query = new MySqlCommand("select * from updatepost", con))
            {
                con.Open();
                var reader = query.ExecuteReader();
                while (reader.Read())
                {
                    PostUpdate post = new PostUpdate();
                    post.id          = reader.GetInt32(0);
                    post.postID      = reader.GetInt32(1);
                    post.title       = reader.GetString(2);
                    post.description = reader.GetString(3);
                    if (!reader.IsDBNull(3))
                    {
                        post.image = reader.GetString(4);
                    }
                    updateposts.Add(post);
                }
            }

            return(updateposts);
        }
Example #2
0
 public string UpdatePost(PostUpdate post)
 {
     try
     {
         con.Open();
         string       sql = "INSERT INTO updatepost (postID, title, description, image) VALUES('" + post.postID + "', '" + post.title + "', '" + post.description + "', '" + post.image + "');";
         MySqlCommand cmd = new MySqlCommand(sql, con);
         cmd.ExecuteNonQuery();
         con.Close();
         return("Data save Successfully");
     }
     catch (Exception ex)
     {
         if (con.State == ConnectionState.Open)
         {
             con.Close();
         }
         return(ex.Message.ToString());
     }
 }