public static List <CompetitiveEvent> GetCompetitiveEvents( this SqlClient client, string sqlCommand) { if (String.IsNullOrEmpty(sqlCommand)) { throw new ArgumentNullException(nameof(sqlCommand)); } SqlConnection connection = null; List <CompetitiveEvent> competitiveEvents = new List <CompetitiveEvent>(); try { using (connection = new SqlConnection(client.ConnectionString)) { connection.Open(); var command = new SqlCommand(sqlCommand, connection); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var category = ReaderToCompetitiveEvent(reader); competitiveEvents.Add(category); } } } return(competitiveEvents); } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { connection.Close(); } }
public static void CreateOrInsert( this SqlClient client, string sqlCommand, Dictionary <string, object> parameters) { if (String.IsNullOrEmpty(sqlCommand)) { throw new ArgumentNullException(nameof(sqlCommand)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } SqlConnection connection = null; try { using (connection = new SqlConnection(client.ConnectionString)) { connection.Open(); var command = new SqlCommand(sqlCommand, connection); command.Parameters.AddRange(DictionaryToParameters(parameters)); command.ExecuteNonQuery(); } } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { connection.Close(); } }
public static void DeleteCompetitiveEvent( this SqlClient client, string sqlCommand, string id) { if (String.IsNullOrEmpty(sqlCommand)) { throw new ArgumentNullException(nameof(sqlCommand)); } if (String.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } SqlConnection connection = null; try { using (connection = new SqlConnection(client.ConnectionString)) { connection.Open(); var command = new SqlCommand(sqlCommand, connection); command.Parameters.AddWithValue(SqlConstants.IdParameterName, id); command.ExecuteNonQuery(); } } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { connection.Close(); } }