More than one table in DataSet
-
DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.
-
DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.
Mazy, try something like this:
DataSet ds = new DataSet("myDataSet");
DataTable t1 = new DataTable("Table1");
DataTable t2 = new DataTable("Table2");ds.Tables.Add(t1);
ds.Tables.Add(t2);HTH -Nick Parker
-
Mazy, try something like this:
DataSet ds = new DataSet("myDataSet");
DataTable t1 = new DataTable("Table1");
DataTable t2 = new DataTable("Table2");ds.Tables.Add(t1);
ds.Tables.Add(t2);HTH -Nick Parker
-
Thanks Nick,I should get table from database,.Should I use second dataadpater to fill the same dataset with second table or there is better way for it? Mazy No sig. available now.
Actually we use each
DataAdapter
to populate or edit only one table(with 4 associateddelete
,update
,insert
andselect
commands). So, for inserting more than one table into adataset
, usually we use more than oneDataAdapter
.
Don't forget, that's
Persian Gulf
not Arabian gulf!
-
Thanks Nick,I should get table from database,.Should I use second dataadpater to fill the same dataset with second table or there is better way for it? Mazy No sig. available now.
Hi, You can write a sql statement like this returning two tables:
"SELECT * FROM People; SELECT * FROM Street;"
That will populate two different tables on your DataSet, the first one containing all the people, and the second one with streets. Hope this helps. Andres Manggini. Buenos Aires - Argentina. -
Hi, You can write a sql statement like this returning two tables:
"SELECT * FROM People; SELECT * FROM Street;"
That will populate two different tables on your DataSet, the first one containing all the people, and the second one with streets. Hope this helps. Andres Manggini. Buenos Aires - Argentina. -
DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.
Try it once with the IDE/Form Designer first: drag a dataAdapter to the form and configure it. Such as "SELECT * FROM Projects". drag another dataAdapter to the form and configure it. Such as "SELECT * FROM People". Now right-click the first dataAdapter icon and choose Generate Dataset. In the form that pops-up choose New Dataset, and name the dataset something like DSAll. This is actually the schema name, but a dataset will be created, named like dsAll1. Now right-click the "other" dataAdpater and choose Generate Dataset. This time, choose "Existing Dataset" and select the dataset you just created. Then you have two dataAdapters (one for each table) which both update data in a single dataset (which contains two tables). You can then look over the Designer generated code to see what it did.
-
Try it once with the IDE/Form Designer first: drag a dataAdapter to the form and configure it. Such as "SELECT * FROM Projects". drag another dataAdapter to the form and configure it. Such as "SELECT * FROM People". Now right-click the first dataAdapter icon and choose Generate Dataset. In the form that pops-up choose New Dataset, and name the dataset something like DSAll. This is actually the schema name, but a dataset will be created, named like dsAll1. Now right-click the "other" dataAdpater and choose Generate Dataset. This time, choose "Existing Dataset" and select the dataset you just created. Then you have two dataAdapters (one for each table) which both update data in a single dataset (which contains two tables). You can then look over the Designer generated code to see what it did.