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
The second option means your reader
will be closed in the event of an exception after it has been created, so it is preferred.
It is effectively transformed by the compiler to:
SqlDataReader reader = command.ExecuteReader();
try
{
....
}
finally
{
if (reader != null)
((IDisposable)reader).Dispose();
}
See MSDN for more info.