【发布时间】:2010-11-14 19:32:16
【问题描述】:
根据我的其他question here about Disposable objects,我们应该在 using 块结束之前调用 Close() 吗?
using (SqlConnection connection = new SqlConnection())
using (SqlCommand command = new SqlCommand())
{
command.CommandText = "INSERT INTO YourMom (Amount) VALUES (1)";
command.CommandType = System.Data.CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
// Is this call necessary?
connection.Close();
}
【问题讨论】:
标签: c# asp.net using sqlconnection sqlcommand