Populating a Strong Typed Multi Table DataSet

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

Guest

C#

I have a DataSet defined in my project that consists of one main table and 3
child tables. I have a SQL statement that can retrieve all the information
for this structure, but how do I populate my dataset in one hit using a
DataAdapter??

I tried to do something liket his:


daRequest.Fill(ResultDataSet.WorkRequest);
daRequest.Fill(ResultDataSet.WorkRequestAction);
daRequest.Fill(ResultDataSet.WorkRequestEffect);
daRequest.Fill(ResultDataSet.WorkRequestNote);
daRequest.Fill(ResultDataSet.Job);

but it fails when it hits the second one as there is not data for that table
for the particular WorkRequest I am dealing with.

My SQL statement looks like this:

SELECT *
FROM WorkRequest LEFT OUTER JOIN
WorkRequestAction ON WorkRequest.WorkRequestObj =
WorkRequestAction.WorkRequestObj LEFT OUTER JOIN
WorkRequestEffect ON WorkRequest.WorkRequestObj =
WorkRequestEffect.WorkRequestObj LEFT OUTER JOIN WorkRequestNote ON
WorkRequest.WorkRequestObj = WorkRequestNote.WorkRequestObj LEFT OUTER JOIN
Job ON WorkRequest.WorkRequestObj = Job.WorkRequestObj
WHERE WorkRequest.WorkRequestObj = " + WorkRequestObj


Am I approaching this from the right way, or cant you do this kind of thing
with a DataAdapter?

Thanks

Steve
 
Hi,

Steve said:
C#

I have a DataSet defined in my project that consists of one main table and
3
child tables. I have a SQL statement that can retrieve all the
information
for this structure, but how do I populate my dataset in one hit using a
DataAdapter??

I tried to do something liket his:


daRequest.Fill(ResultDataSet.WorkRequest);
daRequest.Fill(ResultDataSet.WorkRequestAction);
daRequest.Fill(ResultDataSet.WorkRequestEffect);
daRequest.Fill(ResultDataSet.WorkRequestNote);
daRequest.Fill(ResultDataSet.Job);

but it fails when it hits the second one as there is not data for that
table
for the particular WorkRequest I am dealing with.

My SQL statement looks like this:

SELECT *
FROM WorkRequest LEFT OUTER JOIN
WorkRequestAction ON WorkRequest.WorkRequestObj =
WorkRequestAction.WorkRequestObj LEFT OUTER JOIN
WorkRequestEffect ON WorkRequest.WorkRequestObj =
WorkRequestEffect.WorkRequestObj LEFT OUTER JOIN WorkRequestNote ON
WorkRequest.WorkRequestObj = WorkRequestNote.WorkRequestObj LEFT OUTER
JOIN
Job ON WorkRequest.WorkRequestObj = Job.WorkRequestObj
WHERE WorkRequest.WorkRequestObj = " + WorkRequestObj


Am I approaching this from the right way, or cant you do this kind of
thing
with a DataAdapter?

No you can't do it like this you need a seperate DataAdapter or at least a
seperate query for each DataTable. Or you would need to have a stored
procedure or batch query that returns multiple tables, but joins won't work
to fill related tables....

HTH,
Greetings
 
Back
Top