public List <ForumReply> GetNReplies(int initial, int length) { SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["globaldb"].ConnectionString); string q1 = "SELECT * FROM Reply_Profile_view where published=1 and ThreadId = " + this.ThreadID + " order by DateCreated"; SqlDataReader rdr; SqlCommand com1 = new SqlCommand(q1, con1); con1.Open(); rdr = com1.ExecuteReader(); ForumReply Reply; List <ForumReply> NReplies = new List <ForumReply>(); int n = 1; while (rdr.Read()) { //NThreads = new List<ForumThread>(); Reply = new ForumReply(); Reply.ThreadId = Convert.ToInt32(rdr["ThreadId"]); Reply.ReplyId = Convert.ToInt32(rdr["ReplyId"]); Reply.ReplyBody = rdr["ReplyBody"].ToString(); Reply.Replier = rdr["Replier"].ToString(); Reply.DateCreated = Convert.ToDateTime(rdr["DateCreated"]); Reply.DateModified = Convert.ToDateTime(rdr["DateModified"]); if (rdr["DatePublished"] != DBNull.Value) { Reply.DatePublished = Convert.ToDateTime(rdr["DatePublished"]); } Reply.Published = 1; Reply.ReplierId = Convert.ToInt32(rdr["ReplierId"]); if (n >= initial && n <= initial + length - 1)//improve efficiency { NReplies.Add(Reply); } n++; } con1.Close(); return(NReplies); }
public List<ForumReply> GetNReplies(int initial, int length) { SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["globaldb"].ConnectionString); string q1 = "SELECT * FROM Reply_Profile_view where published=1 and ThreadId = " + this.ThreadID+" order by DateCreated"; SqlDataReader rdr; SqlCommand com1 = new SqlCommand(q1, con1); con1.Open(); rdr = com1.ExecuteReader(); ForumReply Reply; List<ForumReply> NReplies = new List<ForumReply>(); int n = 1; while (rdr.Read()) { //NThreads = new List<ForumThread>(); Reply = new ForumReply(); Reply.ThreadId = Convert.ToInt32(rdr["ThreadId"]); Reply.ReplyId = Convert.ToInt32(rdr["ReplyId"]); Reply.ReplyBody = rdr["ReplyBody"].ToString(); Reply.Replier = rdr["Replier"].ToString(); Reply.DateCreated = Convert.ToDateTime(rdr["DateCreated"]); Reply.DateModified = Convert.ToDateTime(rdr["DateModified"]); if(rdr["DatePublished"]!=DBNull.Value) Reply.DatePublished = Convert.ToDateTime(rdr["DatePublished"]); Reply.Published = 1; Reply.ReplierId = Convert.ToInt32(rdr["ReplierId"]); if (n >= initial && n <= initial + length - 1)//improve efficiency NReplies.Add(Reply); n++; } con1.Close(); return NReplies; }