public List <T> DataTaker(SqlConnection connection) { SqlCommand command = new SqlCommand(SqlExpression, connection); SqlDataReader reader = null; CommandReader commandReader = new CommandReader(command, reader); FunctionSelector <T> functionSelector = new FunctionSelector <T>(commandReader); List <T> listOfProperty = functionSelector.SelectFunctionForCommand(connection); return(listOfProperty); }
public static void SelectFunction(CommandReader commandReader, List <T> listOfProperty) { string commandText = commandReader.Command.CommandText; if (commandText.Contains("INSERT") || commandText.Contains("UPDATE") || commandText.Contains("DELETE")) { int numOfChangedRows = commandReader.Command.ExecuteNonQuery(); Console.WriteLine("The number of rows changed in table: {0}", numOfChangedRows); } else if (commandText.Contains("SELECT")) { commandReader.Reader = commandReader.Command.ExecuteReader(); int fieldCount = commandReader.Reader.FieldCount; if (commandReader.Reader.HasRows) { for (int i = 0; i < fieldCount; i++) { Console.Write("{0} \t", commandReader.Reader.GetName(i)); } Console.WriteLine(); while (commandReader.Reader.Read()) { T listOfPropertyForRow = Convert.ConvertToObject <T>(commandReader.Reader); listOfProperty.Add(listOfPropertyForRow); } } } else { Console.WriteLine("You must enter a SQL text."); } }
public FunctionSelector(CommandReader commandReader) { this.CommandReader = commandReader; }