I use code rush and refactor pro (highlight possible code issues and so on like ReSharper) and they were telling me I had undisposed locals (that implemented IDisposable). So I changed the code to this with two using statements:
using (Reports.StudentRegisters.StudentQueriesDataTable studentDataTable = new Reports.StudentRegisters.StudentQueriesDataTable())
{
using (StudentQueriesTableAdapter studentTableAdapter = new StudentQueriesTableAdapter())
{
try
{
studentTableAdapter.FillByQAbsenceRegRow(studentDataTable, year, school, division, progArea, sinceWeek, missedLessons, includeWdlTrn, ageMin, ageMax, studentGLH);
ds = new DataSet();
ds.Tables.Add((DataTable)studentDataTable);
ReportDocument.SetDataSource(ds.Tables[0]);
}
catch (Exception err)
{
LogReportError(err, this.CrystalViewer, null, ErrorType.Reporting);
}
}
}
Since the studentTableAdapter is used once I could in line it like below:
using (Reports.StudentRegisters.StudentQueriesDataTable studentDataTable = new Reports.StudentRegisters.StudentQueriesDataTable())
{
try
{
(new StudentQueriesTableAdapter()).FillByQAbsenceRegRow(studentDataTable, year, school, division, progArea, sinceWeek, missedLessons, includeWdlTrn, ageMin, ageMax, studentGLH);
ds = new DataSet();
ds.Tables.Add((DataTable)studentDataTable);
ReportDocument.SetDataSource(ds.Tables[0]);
}
catch (Exception err)
{
LogReportError(err, this.CrystalViewer, null, ErrorType.Reporting);
}
}
Obviously in this solution I now have no way to call dispose on the StudentQueriesTableAdapter. Is this called automatically as there is no reference to the object anymore or would this potentially leave something not disposed properly.
I will stress i'm not interested in whether I actually need to use dispose on the two objects, I know some things implement it and it's not really required (Although should always be done). I'm specifically interested in if it is called.