Beispiel #1
0
        //To View all employees details
        public List <Blogs> GetAllBlogs()
        {
            try
            {
                List <Blogs> lstblog = new List <Blogs>();

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetBlogs", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        Blogs blog = new Blogs();

                        blog.id       = Convert.ToInt32(rdr["BlogPostID"]);
                        blog.title    = rdr["BlogPostTitle"].ToString();
                        blog.body     = rdr["BlogPostBody"].ToString();
                        blog.date     = rdr["BlogPostDate"].ToString();
                        blog.username = rdr["BlogUserName"].ToString();

                        lstblog.Add(blog);
                    }
                    con.Close();
                }
                return(lstblog);
            }
            catch
            {
                throw;
            }
        }
Beispiel #2
0
        public Blogs GetBlogByPostID(int PostID)
        {
            try
            {
                Blogs blog = new Blogs();

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetBlogsByBlogPostID", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@BlogPostID", PostID);
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        blog.id       = Convert.ToInt32(rdr["BlogPostID"]);
                        blog.title    = rdr["BlogPostTitle"].ToString();
                        blog.body     = rdr["BlogPostBody"].ToString();
                        blog.date     = rdr["BlogPostDate"].ToString();
                        blog.username = rdr["BlogUserName"].ToString();
                    }
                    con.Close();
                }
                return(blog);
            }
            catch
            {
                throw;
            }
        }