Example #1
0
 public static object GetSubjects()
 {
     using (SqlConnection conn = new SqlConnection(CONN_STRING)) {
         using (SqlCommand cmd = new SqlCommand("select subject from Knowledgebase group by Subject", conn)) {
             conn.Open();
             using (SqlDataReader dr = cmd.ExecuteReader()) {
                 List <Knowledge> subjects = new List <Knowledge>();
                 while (dr.Read())
                 {
                     Knowledge sub = new Knowledge(dr.GetString(0));
                     subjects.Add(sub);
                 }
                 return(subjects);
             }
         }
     }
 }
Example #2
0
 public static List <Knowledge> GetArticles(string Subject)
 {
     using (SqlConnection conn = new SqlConnection(CONN_STRING)) {
         using (SqlCommand cmd = new SqlCommand(" select ID,PostedBy,PostedByLoginID,Title from Knowledgebase where Subject = @Subject",
                                                conn)) {
             cmd.Parameters.AddWithValue("@Subject", Subject);
             conn.Open();
             using (SqlDataReader dr = cmd.ExecuteReader()) {
                 List <Knowledge> lists = new List <Knowledge>();
                 while (dr.Read())
                 {
                     Knowledge item = new Knowledge(dr.GetInt32(0), dr.GetInt32(1), dr.GetString(2), dr.GetString(3));
                     lists.Add(item);
                 }
                 return(lists);
             }
         }
     }
 }