Home >Database >Mysql Tutorial >How to Populate a Dataset with Two Tables Using a Single DataReader?

How to Populate a Dataset with Two Tables Using a Single DataReader?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-30 02:50:40196browse

How to Populate a Dataset with Two Tables Using a Single DataReader?

populating dataset with two tables using single datareader

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn