problem with data relation

Blue man

New member
Joined
Jun 18, 2003
Messages
2
Hello group
I have 2 table with ralation between 2 columns, i created 2 key and one relation between 4 columns. this is done because i wanted to create the child table row for each parent row and copy 2 columns of parent into child table.
when i see the database in a datagrid , it works perfectly , i can add new rows to parent table and the row adds to the child table and copies the 2 column. but when i update the dataset, only the parent table updates . if i add more information and fill more fields on the child table , it will save , but if dont , it wont save.
update commands are like this :

sqlDataAdapter1.Update(dataSet12,"PersonalInfo");

sqlDataAdapter2.Update(dataSet12,"Medication");

i have a dataset with 2 tables and each has 2 key and one relation between 2 table which relates the 2 by 2 columns. the keys are set as allownull , cuz i got some problem regarding adding new rows.
do you have any idea how to solve this problem or any idea how to do that?
ps. im using c# and mostly generated codes. maybe the problem is generated codes.
thanks
 
What is the relationship and how are they being updated via DataGrid compared to updating the DB itself? What does your UPDATE statement look like?

You provided a good amount of information, unfortunately its not detailed information. Give us more detail and possibly show us some code on how youre updating the DB. :)
 
thanks wyrd

i created the relation with toolbox, so there is no code for relation , but i can describe it :
i have two columns , ID and PN , which are used for identification and i have two table "PersonalInfo" and "Medication" . i want to add a row in Medication table whenever i add a row in PersonalInfo table. the keys are ID and PN. the relation is between these 2 columns from PersonalInfo and 2 columns with the same name in Medication.
The sql commans are generated with toolbox also. i havent created the relations in SQL , i created the relation in vs.net . and just added the first tabel to datagrid. so a small like appears below of each row in datagrid.
when i add a row to personalInfo like this :
DataRow myrow = dataSet12.Tables["PersonalInfo"].NewRow();
dataSet12.Tables["PersonalInfo"].Rows.Add(myrow);

and add some information from textboxes and so like this :

int _RowCount = dataSet12.Tables["PersonalInfo"].Rows.Count;
if(_RowCount>0)
{_RowCount--;}
dataSet12.Tables["PersonalInfo"].Rows[_RowCount["FirstName"] = Name_Box.Text.ToString();
dataSet12.Tables["PersonalInfo"].Rows[_RowCount]["SurName"] = Sure_Box.Text.ToString();
dataSet12.Tables["PersonalInfo"].Rows[_RowCount]["PN"]=PN_Box.Text.ToString();
dataSet12.Tables["PersonalInfo"].Rows[_RowCount]["Gener"]=Gener_Cbx.Items[Gener_Cbx.SelectedIndex].ToString();
Name_Box.Text = _RowCount.ToString();

and finaly update the dataadpaters like this :

sqlDataAdapter1.Update(dataSet12,"PersonalInfo");
sqlDataAdapter2.Update(dataSet12,"Medication");

now , when i see the data in database , the PersonalInfo table is full of entered information , but the Medication table is emty, not only one single row is added , but when i add a row i can see in datagrid a row is added and i 2 columns ID and PN have the same value as Personal info , so i consider th relationship is working perfectly.
thank you vermuch helping me :)
 
So its just not updating the Medication table? It sounds like your INSERT command isnt working correctly for some reason. Whats your insert command look like and what are the columns you have in the Medication table?

Oh.. and be sure to add the relationships into your SQL database as well.
 
Back
Top