Search code examples
c#.netdisposeusing

Using the "Using" Statement with Typed Dataset Table Adapters


Simple Question. Is it important to use the using statement when working with typed dataset table adapters? Most examples I have seen on the net never use the using statement.

using (Data_ItemTableAdapter adapter = new Data_ItemTableAdapter())
{

    DataItemTable = a.GetDataByDataItemID(DataItemID);
    // more code here
}

Thanks for your help!!

Edit: Seems like the general consensus is that it is probably a good idea to use "using" in this situation, because it certainly would not hurt, and it doesn't require much effort. Just not sure if it is worthwhile to go back through this old project and change all the code. Thanks for the advice!


Solution

  • If a class implements the IDisposable interface then it is probably safer to wrap the object in a using statment or call the Dispose method manually.

    In this case I don't believe that the data adapter is using any unmanged resources, so the dispose probably doesn't do anything substancial. However, it would be safer to wrap it because in the future it could.