Load dataset with two Selects?

G

Guest

Hi,

I've seen examples of creating multiple DataTables in a dataset with using
two separate Fill() commands with separate SELECTs statements.

However, if you have a stored procedure that returns these two SELECTs in
one call, can you load these results into the dataset as two differnet
DataTables but with one Fill() command?

Dave
 
G

Guest

Thanks, but how to do name the datatables differently with one Fill command?
Do you have any sample links?

Miha Markic said:
Hi Dave,

Yes, you can.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Dave said:
Hi,

I've seen examples of creating multiple DataTables in a dataset with using
two separate Fill() commands with separate SELECTs statements.

However, if you have a stored procedure that returns these two SELECTs in
one call, can you load these results into the dataset as two differnet
DataTables but with one Fill() command?

Dave
 
M

Mike Edenfield

Dave said:
Thanks, but how to do name the datatables differently with one Fill command?
Do you have any sample links?

You need to set up the TableMappings collection for the data adapter.
The DataAdapter will generate names by appending numbers to the first
table name (Table, Table1, Table2, etc.) You can then create data
mappings to rename them:

da.TableMappings.Add("FirstTable1", "SecondTable");
da.TableMappings.Add("FirstTable2", "ThirdTable");
da.Fill(ds, "FirstTable");

--Mike
 
S

Sahil Malik

Yes you can - welcome to batched queries, you don't even need a stored proc
to acheive this result.

By Default the tables will be added as Table and Table1, you would have to
use the TableMappings collection to map the tables to their appropriate
names.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
Please reply to the newsgroups instead of email so everyone can benefit from
your reply.


Dave said:
Thanks, but how to do name the datatables differently with one Fill command?
Do you have any sample links?

Miha Markic said:
Hi Dave,

Yes, you can.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Dave said:
Hi,

I've seen examples of creating multiple DataTables in a dataset with using
two separate Fill() commands with separate SELECTs statements.

However, if you have a stored procedure that returns these two SELECTs in
one call, can you load these results into the dataset as two differnet
DataTables but with one Fill() command?

Dave
 
S

Sahil Malik

Just to be clear, by default the tables will not be called FirstTable1, and
FirstTable2 .. they will actually be Table,Table1,Table2 .. so the mappings
as shown below will have to be slightly altered, though if you read through
the answer given by Mike, he has specified that in the paragraph.
 
M

Mike Edenfield

Sahil said:
Just to be clear, by default the tables will not be called FirstTable1, and
FirstTable2 .. they will actually be Table,Table1,Table2 .. so the mappings
as shown below will have to be slightly altered, though if you read through
the answer given by Mike, he has specified that in the paragraph.

If you pass a table name to DataAdapter.Fill() then the names will be
built using the table you specify:


da.Fill(ds) ==> Table, Table1, Table2, Table3;
da.Fill(ds, "Foo") => Foo, Foo1, Foo2, Foo3

--Mike
 

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

Top