Getting data table parent child relations tostring?

W

What-a-Tool

I am trying to write a program that will take all the members of a data
base, add them to a tree, with all child relations as sub-nodes.

I am having a problem getting the parent child relations for each table &
query.


Dim tblCurrent As DataTable
Dim strTableName As string
For Each tblCurrent In Ds1.Tables
strTableName = tblCurrent.TableName.ToString
Next

This gives me my table names. I can also get column names the same way.

..GetXMLSchema shows me what I want, but I don't want to even think about
dissecting that string data to make it usefull to me.

How can I get the name of any parent or child tables for tblCurrent?


--
Thanks in advance for any help

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
C

Cor

Hi What a tool,

If you use a XML file that has the format of a dataset, you can read it in a
dataset, using by instance the dataset.readXML method

If it has not that format, you have to use it as a XML document.

If it is a dataset you can iterate trough the tables. Asuming you have only
one table you can do that like this (rought written not checked)

\\\
dim myRow as datarow
for each myRow in MyDataset.tables(0).rows
myItem = myrow.item("myitem")
next
///
But for that your XML file has to be a dataset.

If you have more tables you can do this of course also with the tables in a
dataset one by one iterating through the tables.

I hope this helps a little bit?

Cor
 
W

What-a-Tool

I tried the following, but get an "invalid cast exception" on the "dt =
Con.GetOleDbSchemaTable..." line.

I'm using an Access DB.

Can anyone tell me whats wrong here? Thanks in Advance



///

Dim dt As New DataTable()

Ds1.Tables.Add(dt)

dt = Con.GetOleDbSchemaTable(OleDbSchemaGuid.Table_Constraints, New
Object())

Dim f As New frmDG()

f.dg1.DataSource = dt

f.ShowDialog()

\\\


--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
A

Armin Zingler

What-a-Tool said:
I tried the following, but get an "invalid cast exception" on the "dt
= Con.GetOleDbSchemaTable..." line.

I'm using an Access DB.

Can anyone tell me whats wrong here? Thanks in Advance



///

Dim dt As New DataTable()

Ds1.Tables.Add(dt)

dt = Con.GetOleDbSchemaTable(OleDbSchemaGuid.Table_Constraints,
New Object())

Dim f As New frmDG()

f.dg1.DataSource = dt

f.ShowDialog()

\\\


Did you enable Option Strict? In addition, I think the exception shows some
more info.
 
W

What-a-Tool

Thanks to all who helped.
Got my solution from another helpful person in the ADO.Net group

Dim dt As New DataTable()

DsNew.Tables.Add(dt)

Con.Open()

dt = Con.GetOleDbSchemaTable(OleDbSchemaGuid.Table_Constraints, New Object()
{})

Con.Close()

Dim f As New frmDG()

f.dg1.DataSource = dt

f.ShowDialog()



Had to add the {} after new object to make it an array of objects.
--

/ Sean the Mc /



"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 

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