Parent-Child data-entry form

XZcute

New member
Joined
Mar 2, 2007
Messages
3
Programming Experience
3-5
Hi all,

I'm developing an application for a hospital, but I'm having some trouble with my data-entry form...
I'll do my best to explain the situation in detail:

Basically I have 3 Tables:

Patient
Admission
Surgery

Patient can have one or many Admissions
During a single admission the patient can need one or many Surgeries

On my form I have 3 bindingsources with the tableadapters etc. (1 for each table)

The users who need to enter this data need to see all this as if it is 1 record ... all data-entry controls are on a single form

At the moment when I click "New" this is what should happen
- They select a patient
- PatientBindingSource.position = selected patient
- AdmissionBindingSource.Addnew()
- Fill in all the admission information
- Click "Add Surgery"
- SurgeryBindingsSource.Addnew()
- Fill in all the surgery information
- Save to database

I expected that when I perform "addnew" on a Child BindingSource the PK from the Parent Bindingsource would be set in the FK field from the child bindingsource...

But this clearly isn't the case... Anybody know how to do this??

Thanks in advance!
 
i would do that as follows:
-Create databound combobox of patients display member = name? valuemember = PK
- They select a patient from a combobox
- AdmissionBindingSource.Addnew()
- display a panel (which was previously visable = false) with the admission controls and use code to enter the new Primary key, eg, patient_fktextbox.text = ComboBox.SelectedVale
-set the text box to read only


is this what you mean? (this is presuming you are using detail views and not datagrid views)
 
I expected that when I perform "addnew" on a Child BindingSource the PK from the Parent Bindingsource would be set in the FK field from the child bindingsource...

But this clearly isn't the case... Anybody know how to do this??

It is if you set the relationships up correctly, and also you ensure that the bindingsources point to each other for their relationship, not the original tables

i.e.
patientBS binds to patient table
admissionBS binds to patientBS.PatientAdmissionRelation
surgeryS binds to admissionBS.AdmissionSurgeryRelation

I storngly recommend your add new code looks like:



Sub NewPatient()
patientBS.AddNew()
patientBS.EndEdit()
NewAdmission()
End Sub

Sub NewAdmission()
admissionBS.AddNew()
admissionBS.EndEdit()
New Surgery()
End Sub

Sub NewSurgery()
surgeryBS.AddNew()
surgeryBS.EndEdit()
End Sub


If you DONT endedit right after you addnew, then you will mysteriously find that your related data disappears, its very annoying if you do this:

patientBS.AddNew()
admitBS.AddNew()
surgeryBS.AddNew()
(let the user edit the data)
patientBS.EndEdit()
(at this point all the new data they typed from admit and surgery just *disappears*)
 
If you DONT endedit right after you addnew, then you will mysteriously find that your related data disappears,

Cjard, I've just tried this in an app I'm working on.

If I put endedit after addnew I get an error "column x does not allow nulls".

However, I'm having the same issue as the OP.

grid a is bound to bindingsource a
grid b is bound to bindingsource a relationship

If I add a new row to A, it saves fine and I get an ID back from the DB.

If I then try to add a row to B, I get an "ID field cannot be null" error.
 
Back
Top