Do I really need to use comm.Dispose()
and conn.Dispose()
or directly used the using
?
using (OdbcConnection conn = new OdbcConnection())
{
conn.Open();
OdbcCommand comm = new OdbcCommand(sql, conn);
OdbcDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
//codes here...
}
conn.Close();
dr.Close();
comm.Dispose();
conn.Dispose();
}
If that is the case, I'm thinking to do this.
Snippet:
using (OdbcConnection conn = new OdbcConnection())
{
conn.Open();
using(OdbcCommand comm = new OdbcCommand(sql, conn))
{
using(OdbcDataReader dr = comm.ExecuteReader())
{
while (dr.Read())
{
//codes here...
}
}
dr.Close();
}
conn.Close();
}
Would this be more appropriate?