Tech Off Post

Single Post Permalink

View Thread: ADO.Net feature request
  • User profile image

    Thanks for the post!

    As has been observed, this can be achieved using TableMappings, for example, the following code writes out the table names "Customers" and "Orders":

    SqlConnection sqlConn = new SqlConnection(connString);
    SqlDataAdapter sqlAdapter = 
       new SqlDataAdapter("SELECT * FROM Customers;SELECT * FROM Orders", sqlConn);

    DataSet ds = new DataSet();
    foreach(DataTable t in ds.Tables)

    Alternatively, in ADO.NET 2.0 we added a Load() command that allows you to directly load a datatable or dataset from any datareader, without requiring you to create a DataAdapter.  The Load() command does take an optional string of tablenames, so you could write the code as follows:

    SqlConnection sqlConn = new SqlConnection(connString);
    DataSet ds2 = new DataSet();
    SqlCommand command = 
                new SqlCommand("SELECT * FROM Customers;SELECT * FROM Orders",sqlConn);
    SqlDataReader reader = command.ExecuteReader;(CommandBehavior.CloseConnection);
    foreach(DataTable t in ds2.Tables)

    Given this direct mechanism, and a desire to avoid having too many overloads, we decided not to add another variation of overloads to Fill.

    We could certainly revisit this decision if people feel this scenario is common/important enough to justify additional overloads, but our general feeling was that having too many overloads made the API more confusing.