I'm trying to fill DataRelation collection by information, read from database.
DataTable schemaTable =
oleconnection.GetOleDbSchemaTable(
OleDbSchemaGuid.Foreign_Keys,
new object[] { null, null, tablename });
But this info doesn't say anything about is it real foreign key constraint or just relation and, because of this, I don't know what value to set for the fourth parameter of DataRelation constructor (createConstraints).
public DataRelation(
string relationName,
DataColumn[] parentColumns,
DataColumn[] childColumns,
bool createConstraints
)
Particularly, in MS Access one could connect two tables with relation but not enforce data integrity check. Some additional research showed that such unenforced relations appear in OleDbSchemaGuid.Referential_Constraints schema table too.
I am wondering where can I get required information. Please show me the way.
It's not possible to fetch the additional attributes related to a relation in MSAccess using Ado.Net. It was possible only in VBA using DAO.
All the relations and their additional attributes are stored in
MSysRelationshipstable in every version of ms-access. The fieldgrbithas values for all possible attributes of a relation i.e. Enforce Referential Intigrity, Cascade Delete, Cascadde Update. Other fields of this table are self explanatory and those are same with the fields returned by GetOleDbSchemaTable method.Some useful calculation for Grbit:
Sample code to access the table in c#:
See also:
Note: It's not possible to fetch the extra information related to relation in MS-Access through
GetOleDbSchemaTable. Oledb is an wrapper only on the database andAccessis not exposing ths information to outer world, so it's not possible to fetch the information withADO.netin direct maner.So for workaround, you need to access and manipulate only
grbitcolumn information ofMSysRelationshipstable.