Master/Detail Dataset/Dataview

  • Thread starter Thread starter angela
  • Start date Start date
A

angela

Hi

I have two select statements, one pulling out the contacts and one
pulling out the primary address of the contact (if there is one)

And I would like to populate the dataset or rearrange a dataset so it's
arranged like this

contact
address
contact
address etc....

I am NOT using it in conjunction with a control but wanting to export
the whole dataset into excel.

e.g. exportToExcel.Dataview = ContactAndAddressDS.table(0).defaultview

Any ideas?

Thanks
Angela
 
I would use one select statement which returns the name and address, maybe
something like this:

SELECT T1.contact_name, T2.addr
FROM T1 LEFT JOIN T2 ON T1.contact_id = T2.contact_id;

The left join will return all contacts - T2.addr will be null if there's no
address in the T2 table.

Use it to create a data reader.

dim dt as new datatable
dim dr as datarow
dt.Columns.Add("name", GetType(String))

while sqldr.Read
dr = dt.NewRow
dr(0) = dqldr.GetString(0) 'Contact
dt.Rows.Add(dr)
dr = dt.NewRow
if isdbnull(sqldr(1)) then
dr(0) = "No address on file"
else
dr(0) = sqldr.GetString(1) 'Address
end if
dt.Rows.Add(dr)
end while

Then you can put the dt into a dataset if you want.
 
Back
Top