public List<Entities.Topic> GetTopics(int sectionID) { List<Entities.Topic> listTopic = new List<Entities.Topic>(); try { using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["LoginDb"].ConnectionString)) { SqlCommand cmd = new SqlCommand("GetTopics", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("sectionID", sectionID); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //проверка входных данных на DBNull.Value int? idLastMess = null; if (reader["IDLastMess"] != DBNull.Value) idLastMess = Convert.ToInt32(reader["IDLastMess"]); int? userIDLastMess = null; if (reader["IDLastMess"] != DBNull.Value) userIDLastMess = Convert.ToInt32(reader["IDLastMess"]); DateTime? dataLastMess = null; if (reader["DataLastMess"] != DBNull.Value) dataLastMess = (DateTime)reader["DataLastMess"]; Entities.Topic topic = new Entities.Topic( Convert.ToInt32(reader["ID"]), reader["Name"].ToString(), Convert.ToInt32(reader["UserID"]), reader["Login"].ToString(), (DateTime)reader["AddDate"], (reader["countReply"] != DBNull.Value) ? Convert.ToInt32(reader["countReply"]) : 0, idLastMess, //(reader["IDLastMess"] != DBNull.Value)?Convert.ToInt32(reader["IDLastMess"]):null, userIDLastMess, (reader["UserLoginLastMess"] != DBNull.Value) ? reader["UserLoginLastMess"].ToString() : "", dataLastMess ); listTopic.Add(topic); } } } catch (Exception e) { ErrorDAL.AddNewError(DateTime.Now, e.ToString(), ""); throw new Exception("Oшибка данных"); } return listTopic; }
public List <Entities.Topic> GetTopics(int sectionID) { List <Entities.Topic> listTopic = new List <Entities.Topic>(); try { using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["LoginDb"].ConnectionString)) { SqlCommand cmd = new SqlCommand("GetTopics", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("sectionID", sectionID); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //проверка входных данных на DBNull.Value int?idLastMess = null; if (reader["IDLastMess"] != DBNull.Value) { idLastMess = Convert.ToInt32(reader["IDLastMess"]); } int?userIDLastMess = null; if (reader["IDLastMess"] != DBNull.Value) { userIDLastMess = Convert.ToInt32(reader["IDLastMess"]); } DateTime?dataLastMess = null; if (reader["DataLastMess"] != DBNull.Value) { dataLastMess = (DateTime)reader["DataLastMess"]; } Entities.Topic topic = new Entities.Topic( Convert.ToInt32(reader["ID"]), reader["Name"].ToString(), Convert.ToInt32(reader["UserID"]), reader["Login"].ToString(), (DateTime)reader["AddDate"], (reader["countReply"] != DBNull.Value) ? Convert.ToInt32(reader["countReply"]) : 0, idLastMess, //(reader["IDLastMess"] != DBNull.Value)?Convert.ToInt32(reader["IDLastMess"]):null, userIDLastMess, (reader["UserLoginLastMess"] != DBNull.Value) ? reader["UserLoginLastMess"].ToString() : "", dataLastMess ); listTopic.Add(topic); } } } catch (Exception e) { ErrorDAL.AddNewError(DateTime.Now, e.ToString(), ""); throw new Exception("Oшибка данных"); } return(listTopic); }