>> string sqlSelectString = "select * from mytable where 1=1"; >> SqlDataAdapter oDataAdapter = new SqlDataAdapter( sqlSelectString, connectionString); >> DataSet dsDataSet = new DataSet(); >> oDataAdapter.Fill( dsDataSet); >>>>
string sqlSelectString = "select * from mytable where 1=1"; DataSet dsDataSet; using (SqlDataAdapter oDataAdapter = new SqlDataAdapter(sqlSelectString, connectionString)) { dsDataSet = new DataSet(); oDataAdapter.Fill(dsDataSet); }which is pretty much the equivalent of:
{ SqlDataAdapter oDataAdapter = new SqlDataAdapter(sqlSelectString, connectionString); try { dsDataSet = new DataSet(); oDataAdapter.Fill(dsDataSet); } finally { if (oDataAdapter != null) oDataAdapter.Dispose(); } }Note that generally you should *not* declare the IDisposable (in this case oDataAdapter) outside the using statement. If you do that it will remain in scope even though it has been disposed.