Which of the following two examples are correct? (Or which one is better and should I use)
In the MSDN I found this:
private static void ReadOrderDat
Would it not be simpler to use this code?
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, CommandType.Text, queryString))
{
// Call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
}
This should dispose of the reader, and the implicit connection and command when the using is terminated.
Or have I missed something?