Datasets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can one dataset be directly populated with tables from different sources?

Example:
There are 3 .mdb files, with the same schema, and I want 2 tables from each
file. Is there a way I can just create one dataset and put all the tables
into that dataset? (versus creating a dataset for each .mdb then merging the
datasets)


Thanks,
~ Yuki
 
Yes, you can. Just pass the same data set object to all the Fill() method
calls of the data adapter, perhaps with a different table name each time.

Can one dataset be directly populated with tables from different sources?

Example:
There are 3 .mdb files, with the same schema, and I want 2 tables from each
file. Is there a way I can just create one dataset and put all the tables
into that dataset? (versus creating a dataset for each .mdb then merging
the
datasets)


Thanks,
~ Yuki
 
Let's see if I understand...

The Fill() method is called through a table adapter or data adapter and
passed a dataset, which it will fill. Right now I have 3 different table
adapters, because I have 3 separate .mdb files, so the code looks like:

this.TableAdapter.Fill(this.DataSet.table1); // from
a.mdb
this.TableAdapter1.Fill(this.DataSet2.table1); // from b.mdb
this.TableAdapter2.Fill(this.DataSet3.table1); // from c.mdb

If I were to change the part that says DataSet* to just DataSet, in the Fill
method, the complier gives me errors. I'm assuming this is because the table
adapters only like their personal datasets, because of possible schema issues?

Would I need to create a new dataset and define a schema? Or is the issue
with the table adapters?


Thanks,
~ Yuki
 
How about something like this.

using (SqlConnection conn = new SqlConnection(dsn))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;

cmd.CommandText = "Select * from database1file"

using (SqlDataAdapter da = new SqlDataAdapter())
{
using (DataSet ds = new DataSet())
{

da.SelectCommand = cmd;
da.Fill(ds, "1stTable");

cmd.CommandText = "Select * from database2file"
da.SelectCommand = cmd;
da.Fill(ds, "2ndTables");
}
}
}
}
}
 
Did you try Mel's code?

Let's see if I understand...

The Fill() method is called through a table adapter or data adapter and
passed a dataset, which it will fill. Right now I have 3 different table
adapters, because I have 3 separate .mdb files, so the code looks like:

this.TableAdapter.Fill(this.DataSet.table1); // from
a.mdb
this.TableAdapter1.Fill(this.DataSet2.table1); // from
b.mdb
this.TableAdapter2.Fill(this.DataSet3.table1); // from
c.mdb

If I were to change the part that says DataSet* to just DataSet, in the Fill
method, the complier gives me errors. I'm assuming this is because the
table
adapters only like their personal datasets, because of possible schema
issues?

Would I need to create a new dataset and define a schema? Or is the issue
with the table adapters?


Thanks,
~ Yuki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top