Example of conversion between DataTable and DataSet in ES0en. NET

  • 2020-07-21 07:29:30
  • OfStack

DataSet contains multiple DataTable and constraints between DataTable.
If your data does not need relational mapping, DataTable is more efficient. If you need a relational query like 1:N or N:M, populate all of the corresponding DataTable in DataSet and use the relational query data.

DataSet data source You can think of it as a database, and DataTable is a table in the database

Add DataTable to DataSet:

When DataTable cannot be directly converted to DataSet in the project,

Can first new
new DataSet c can come out and fill it
DataSet ds = new DataSet();
DataTable dt= new DataTable("Customers");

ds.Tables.Add(dt);

Read one DataTable in DataSet:

dt = ds. Tables [0]; // Specify the 0th table

dt = ds. Tables [" Customers "]; // Specify a table named "Customers"

Related articles: