In actual scenarios, you may need to query the table sheets in the database at a time,
Fill the dataset with the fill method of the sqldataadapter class, and specify the name of the able table filled in the dataset,
For example, set it to the same as the database.
You can use the tablemappings attribute of the sqldataadapter class.
Fill in the table name in dataset with the fill method of the sqldataadapter class. The default value is table, Table1, Table2 ......
Sqlconnection conn = new sqlconnection ("Server =.; database = databasename; uid = sa; Pwd = sa"); // you can define a database connection.
String SQL = "select * from user; select * from product; select * from article ;";
Sqlcommand cmd = new sqlcommand (SQL, Conn );
Sqldataadapter adapter = new sqldataadapter (CMD );
// Specify the table name, tablemappings. Add method. The first parameter is the default table name for fill dataset, and the second parameter is the specified table name, which can be customized as needed.
Adapter. tablemappings. Add ("table", "user ");
Adapter. tablemappings. Add ("Table1", "product ");
Adapter. tablemappings. Add ("Table2", "article ");
Dataset DS = new dataset ();
Adapter. Fill (DS );
// There are three tables filled in the dataset: User, product, and article.
In this way,
It is easy to associate multiple tables (tables filled with dataset) returned by the query with the tables in the database for convenient use in the program.