populating dataset from database tables via datareader is easiest task howewer, in case of one to many relation problem occurs in populating child tables along with master tables. to resolve this problem multiple select statement can be sent to database in single request as
select * from field1; select * from field2
data adapter created from this query will automatically assign table names as table, table1, table2 and so on. To overwrite these generated names, tablemappings property is to be used as
SqlDataAdapter adapter = new SqlDataAdapter( "SELECT * FROM Customers; SELECT * FROM Orders", connection); adapter.TableMappings.Add("Table", "Customer"); adapter.TableMappings.Add("Table1", "Order"); adapter.Fill(ds);
where adapter is data adapter created for populating dataset and customer and order are predifined table names.
The above is the detailed content of How to Populate a Dataset with Two Tables Using a Single DataReader?. For more information, please follow other related articles on the PHP Chinese website!