Query in Datareader
Posted
by bala
on Stack Overflow
See other posts from Stack Overflow
or by bala
Published on 2010-04-08T09:23:51Z
Indexed on
2010/04/08
11:23 UTC
Read the original article
Hit count: 416
ADO.NET
Hi All,
In the below code,
using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
_emailTemplate.EmailContent = dr["EMAILCONTENT"].ToString();
_emailTemplate.From = dr["EMAILFROM"].ToString();
_emailTemplate.Subject = dr["EMAILSUBJECT"].ToString();
}
}
I understand CommandBehavior.CloseConnection will close the connection object when datareader is closed. In the above code, when we use using with SqlDataReader, will it close the datareader before disposing it? in other other words, if i use using statement do i need to close the datareader manually?
© Stack Overflow or respective owner