M
M
Hi all,
I have code like:
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
// do something here
}
else
{
reader.Close(); // this is the line I'm not sure about
Response.Redirect("to_some_other_page.aspx");
}
reader.Close();
My question is:
Is reader.Close() in the else part really needed? If reader.Read() returns
nothing, then is the reader actually open or not?
The code above does not crash, but maybe the Close() is redundant...
Thanks.
I have code like:
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
// do something here
}
else
{
reader.Close(); // this is the line I'm not sure about
Response.Redirect("to_some_other_page.aspx");
}
reader.Close();
My question is:
Is reader.Close() in the else part really needed? If reader.Read() returns
nothing, then is the reader actually open or not?
The code above does not crash, but maybe the Close() is redundant...
Thanks.