SqlDataAdapter with using keyword

大城市里の小女人 提交于 2019-12-01 19:14:11

Healthy-ish; personally I'd say the unhealthy bit is the bit where it makes use of DataSet and DataAdapter, but that is perhaps just my personal bias.

Yes, you should dispose the adapter etc here (which is what the using does for you, obviously).

As a trivial pointless tidy, you can stack the usings - just makes it a little less verbose:

using (SqlConnection con = new SqlConnection(ConStr))
using (SqlCommand cmd = con.CreateCommand())
{

It will be enough to leave just the first using (the one on the Connection) because disposing the connection will dispose everything you need disposed.

However, there is no harm disposing everything, just a bit more code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!