using (var connection = new SqlConnection("user id=xxx;" +
"password=xxx;server=xxx;" +
"Trusted_Connection=yes;" +
"database=xxx; " +
"connection timeout=30"))
{
connection.Open();
string sql = "SELECT * FROM testTable";
using (var command = new SqlCommand(sql, connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
.
.
.
.
.
}
}
}
}
The code above can be used to retrive the list of rows of records and display them in my C# console application but it will be very messy to be in Main method. I'm wondering how to handle this chunk of records and store them into a list or something by calling a method. Will it be possible in C# console application?