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
Release: 2024-12-30 02:50:40
Original
186 people have browsed it

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
Copy after login

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);
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template