error (datasets)

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello,following this code I got an error message:

the code:
System.Data.DataRelation dr;
System.Data.DataColumn dc1;
System.Data.DataColumn dc2;
// Get the parent and child columns of the two tables.
dc1 = ds.Tables[0].Columns[0];
dc2 = ds.Tables[1].Columns[0];
dr = new System.Data.DataRelation("db", dc1, dc2);
ds.Relations.Add(dr);

the error:
An unhandled exception of type 'System.Data.InvalidConstraintException'
occurred in system.data.dll

Additional information: Parent Columns and Child Columns don't have
type-matching columns.

Could someone explain me why? Thanks a lot!
 
HI juli

Did you check the data type of both the fields in the table that you are
trying to create the relation between. They need to match exactly to create a
valid relation.

pradeep_TP
 
Juli,

What is the type of
dc1 = ds.Tables[0].Columns[0];
dc2 = ds.Tables[1].Columns[0];

Cor
 
hi,

you did not paste the part where you especify the types of the columns, but
according to the error you are not using the same type, I will strongly
advise you to use the VERY same type in both tables.


cheers,
 
Back
Top