我正在开发一个需要访问数据库的应用程序。使用“using”语句是很好的选择,因为它能确保对象得到正确处理并且不需要显式代码来实现这一点。
所以我有些困惑,在哪里使用“using”,在哪里则不需要。
public int route(Route r)
{
try
{
using (SqlConnection con = new SqlConnection(connectionString))
{
using(SqlCommand com = new SqlCommand("",con))
{
using (SqlDataReader sdr = com.ExecuteReader())
{
}
}
}
}
catch (Exception e)
{
}
}