/// <summary> /// Returns an existing lecturersData object with the specified ID /// </summary> public static Lecturer GetDetailsByID(int sRefID) { try { using (MySqlConnection cn = new MySqlConnection(connectionString)) { MySqlCommand cmd = new MySqlCommand(SP_GET_BYID, cn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ref_id", sRefID); cn.Open(); IDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { // return new lecturersData( // (int) reader["Id"], (string) reader["Name"], (string) reader["Surname"], (string) reader["EmailAddress"]); return(Lecturer.Parse(reader)); // Use this to avoid null issues } else { return(null); } } } catch (Exception ex) { // Put your code for Execption Handling here // 1. Log the error // 2. Handle or Throw Exception // This is my code...Customized!!!! // Note: You may modify code generation template by editing ExceptionHandler CodeBlock throw ex; } }
/// <summary> /// The purpose of this method is to get all lecturers data based on the Filter Expression criteria. /// </summary> /// <param name="filterExpression">A NameValueCollection object that defines various properties. /// For example, filterExpression - Where condition to be passed in SQL statement. /// </param> /// <returns>List of lecturersData object</returns> public static List <Lecturer> GetList(string filterExpression) { try { using (MySqlConnection cn = new MySqlConnection(connectionString)) { filterExpression = (string.IsNullOrEmpty(filterExpression) ? string.Empty : "WHERE " + filterExpression.Trim()); string strSQL = string.Format(SP_GET_FILTER, filterExpression); using (MySqlCommand cmd = new MySqlCommand(strSQL, cn)) { cmd.CommandType = CommandType.Text; cn.Open(); IDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); List <Lecturer> objList = new List <Lecturer>(); while (reader.Read()) { //objList.Add(new lecturersData( // (int) reader["Id"], (string) reader["Name"], (string) reader["Surname"], (string) reader["EmailAddress"])); objList.Add(Lecturer.Parse(reader)); // Use this to avoid null issues } return(objList); } } } catch (Exception ex) { // Put your code for Execption Handling here // 1. Log the error // 2. Handle or Throw Exception // This is my code...Customized!!!! // Note: You may modify code generation template by editing ExceptionHandler CodeBlock throw ex; } }