I have the following code.
private DataTable LoadSMSCellProviders() { string sqlQuery = "Select * from SMSAddress"; DataTable dt = new DataTable(); using (SqlConnection conn = new SqlConnection(Utility.ConnString)) { using (SqlCommand command = new SqlCommand(sqlQuery, conn)) { SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dt); return dt; } } }
Microsoft code analysis tells me that dt
doesn't fit along all the execution paths, but I'm not sure how to fix this. If I try to call dispose
on it before return
, it will return a null value, and if I try to do this at the end of the method, the code will never be reached ...
What am I missing here?
This is a message from an analysis tool:
warning: CA2000: Microsoft.Reliability: in the 'xx ()' method, the 'dt' object is not located on all exception paths. Calling System.IDisposable.Dispose on the 'dt' object before all references to it is out of scope.
source share