New Question about Adding :)

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Now that I have the @@Identity issue solved, I've noticed a little problem when adding a new record with child data.

It's to do with heirachical (spelt wrong i know) - If I enter the data on the main form for my first table, and submit, the data goes into the SQL server to table1 correctly.
However, if I then try to add a record to the datagrid which should show child data, I get an error bombing my out on table2's primary key ID field - "Tab2ID cannot be null".

My datagrid is set to read only, and I open a form using currency manager to edit the current selected record in the datagrid.

The weird thing is, if I go into SQL and add manually to the table, I can then open the other form (set up the same) to view the data, and add data to the datagrid.

Problem only happens when adding new table1 fields with child data to table2.

Is this a common problem as I've actually got the same errors with some examples I've downloaded.

Cheers
Luke
 
OK, no answers so I'll try to explain as much as possible.

I have 3 main tables, for instance Tab1, Tab2 and Tab3. In that order is the way parent-to-child works.

When a new record is added to Tab1, then data can be added to Tab2. When data is present in Tab2, data can be added to Tab3.

Tab1: Field1_ID

Tab2: Field1_ID, Field2_ID

Tab3: Field1_ID, Field2_ID

I've created a form to add new records to my database. On the first tab of the form, information for Tab1 is shown, and can't click onto the second tab until they have submitted this new record to the database. On the second tab of the form, there are two datagrids, 1 for Tab2, 1 for Tab3.

If I enter data into the 1st datagrid and click Submit, changes are saved to the database, and the data is shown relational, i.e. that record entered has the Field1_ID set the same.

However, when I go to add data to the second Datagrid, even though now both Field1_ID and Field2_ID exist in Tab2, I get an error of:

ForeignKeyConstraint Tab2_Tab3 requires the child key values (1, ) to exist in the parent table. Do you want to correct the value?
NOTE: (1, ) is the number assigned to Field1_ID. and this does exist in the parent table (I'm assuming because of the relation, it's talking about Tab2).

My constraints in Tab2 are working fine. Basically Field1_ID can exist as many times as possible, but Field2_ID must be different, so you get 1-1, 1-2, 1-3, 1-4, 1-5, but 1-5 can't be entered again as it exists.

Any help on this would be most appriciated, I think it's because I'm trying to update to 3 tables and I'm just missing something simple....

Cheers,
Luke
 
I've tried another way - I have set the datasource and datamember to be automatic, to see whether Field1_ID and Field2_ID show correctly in the table.

This problem only happens when adding a new record from scratch. I can use Tab3 to enter data on another form with the datagrid set up the same.

I've attached a screen shot to show the problem - Rev No is the heading name, however the mapping name is set to DWRSequence.
DWRNumber is cascading correctly from Tab1 (where it is assigned on Submit) through to Tab3, however DWRSequence is the number entered in the second Datagrid (in the case of the screenshot 1), so the DataGrid for Tab3 should show DWRNumber = 11, DWRSequence = 3.

But it isn't....and I've been stuck all day working out why...
 

Attachments

  • image.jpg
    image.jpg
    29.1 KB · Views: 101
I've figured it out - the problem is to do with the way RustemSoft programs the relationships.
I'm using RustemSoft DataGridColumns .NET Assembly package, and even though the 3rd Datagrid is set to the correct relationship (having to go all the way from the first table through), it doesn't actually pick it up.

Setting the DataSource and DataMember of the grid manually works, so looks like it isn't an issue with my coding as first thought.

Thanks for the help (myself) :)
 
Back
Top