|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datarelation HELP needed - Constraints, M-2-MBack again with more questions. I have a task at hand and I'm trying to use a datarelation between two datatables. Table1 = Trans fields= date, product, dept, assignto, ..... 04/01/06 Clamp 54 <blank> 04/01/06 Valve 55 <blank> 04/01/06 Body 54 <blank> Table2 = Staff fields= dept, person, ..... 54 Alice 54 Tom 55 Bob 55 Mary 55 Robert I've set up 2 datagrids with each of the tables attached, now I want to relate the Trans table to the Staff table using the dept as the related columns. Here's my code. Dim data_relation As New DataRelation("Trans-Staff", _ ds.Tables("Trans").Columns("TRDept"), _ ds.Tables("Staff").Columns("STDept")) ds.Relations.Add(data_relation) When I go to execute, it fails on the ds.relations.add line and comes up with this error. --------------------------------- An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll Additional information: These columns don't currently have unique values. --------------------------------- The objective is to show all Trans in grid 1, and as a row is selected, show only the Staff for the department that is selected in grid 1. From there, one row of the staff will be selected (being assigned to that transaction). I then plan to update the Staff row with some info and update the trans with the person assigned from the Staff table and other information. I'm sure this has been done before. Any full examples would be appreciated, but right now I need to fix this datarelation problem. Thanks, Hexman Hi,
Are your datacolumn names "dept", or are they "TRDept" and "STDept"? If actually "dept", then Dim data_relation As New DataRelation("Trans-Staff", _ > ds.Tables("Trans").Columns("dept"), _ You will get an ArgumentNullException from the constructor if one or both of > ds.Tables("Staff").Columns("dept")) > ds.Relations.Add(data_relation) the DataColumn objects contains a null reference. JT -- Show quoteJohn "Hexman" wrote: > Hello all, > > Back again with more questions. I have a task at hand and I'm trying > to use a datarelation between two datatables. > > Table1 = Trans > fields= date, product, dept, assignto, ..... > > 04/01/06 Clamp 54 <blank> > 04/01/06 Valve 55 <blank> > 04/01/06 Body 54 <blank> > > Table2 = Staff > fields= dept, person, ..... > > 54 Alice > 54 Tom > 55 Bob > 55 Mary > 55 Robert > > I've set up 2 datagrids with each of the tables attached, now I want > to relate the Trans table to the Staff table using the dept as the > related columns. Here's my code. > > Dim data_relation As New DataRelation("Trans-Staff", _ > ds.Tables("Trans").Columns("TRDept"), _ > ds.Tables("Staff").Columns("STDept")) > ds.Relations.Add(data_relation) > > When I go to execute, it fails on the ds.relations.add line and comes > up with this error. > --------------------------------- > An unhandled exception of type 'System.ArgumentException' occurred in > system.data.dll > > Additional information: These columns don't currently have unique > values. > --------------------------------- > > The objective is to show all Trans in grid 1, and as a row is > selected, show only the Staff for the department that is selected in > grid 1. From there, one row of the staff will be selected (being > assigned to that transaction). I then plan to update the Staff row > with some info and update the trans with the person assigned from the > Staff table and other information. > > I'm sure this has been done before. Any full examples would be > appreciated, but right now I need to fix this datarelation problem. > > > Thanks, > > Hexman > > > JT,
The actual names of the fields are "TRDept" & "STDept". Both are defined as text fields with a length of 3. Hexman On Wed, 19 Apr 2006 18:49:03 -0700, JT <Jthayer@online.nospam> wrote: Show quote >Hi, >Are your datacolumn names "dept", or are they "TRDept" and "STDept"? If >actually "dept", then > >Dim data_relation As New DataRelation("Trans-Staff", _ >> ds.Tables("Trans").Columns("dept"), _ >> ds.Tables("Staff").Columns("dept")) >> ds.Relations.Add(data_relation) > >You will get an ArgumentNullException from the constructor if one or both of >the DataColumn objects contains a null reference. > >JT As long as you have added the columns in question to your datatable BEFORE
you try to create the relationship, and your relationship constructor uses the names of the COLUMNS, (not necessarily the fields), you should not have any problem. JT Show quote > JT, > > The actual names of the fields are "TRDept" & "STDept". Both are > defined as text fields with a length of 3. > > Hexman > > > On Wed, 19 Apr 2006 18:49:03 -0700, JT <Jthayer@online.nospam> wrote: > > >Hi, > >Are your datacolumn names "dept", or are they "TRDept" and "STDept"? If > >actually "dept", then > > > >Dim data_relation As New DataRelation("Trans-Staff", _ > >> ds.Tables("Trans").Columns("dept"), _ > >> ds.Tables("Staff").Columns("dept")) > >> ds.Relations.Add(data_relation) > > > >You will get an ArgumentNullException from the constructor if one or both of > >the DataColumn objects contains a null reference. > > > >JT > |
|||||||||||||||||||||||