detect FK in dataTable

  • Thread starter Thread starter Emre DÝNÇER
  • Start date Start date
E

Emre DÝNÇER

Dear All,
is it possible to extract the DataColumn which is a foreign key of another
table. The DataTable has only one table.

foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {

Console.WriteLine("123");

console.WriteLine(dr.ParentTable.TableName.ToString());

}

prints nothing unfortunately..
 
Hi,


--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Emre DÝNÇER said:
Dear All,
is it possible to extract the DataColumn which is a foreign key of another
table. The DataTable has only one table.

I do not understand the above, The DataRelation has all the properties you
need for knowing the parent/child tables and columns.

Are you sure you have a FK ?
 
Emre,

I think you mean the DataSet only has one table.

The DataRelation instances that are exposed by the DataSet class are the
in-memory representations of the relations between the DataTable instances.
Unless they are constructed and placed in the data set, they won't be there.
Usually, the designer will create the relations between the data tables for
you when you drag and drop tables from the server explorer to the data set
designer.

However, since you say you only have one data table in the data set, I
don't see how you can have any relations represented locally, because you
don't have another data table to relate to.

That being said, if you need relation information from the database, you
are going to have to query the database for it.
 
Back
Top