Hi,
I am new to .Net. and i am writing a winforms app for adding and updating records.
I have a dataset with 2 tables. A parent table & associated child table.
I created a data-relation, so that when a record on the parent table is selected (the + sybmbol clicked) it reveals the corresponding rows of the child table .
this is wat i did
***********************************************************************
sqlDataAdapter1.Fill(dataSet1,"table1");
sqlSelectCommand1.CommandText = "select * from [table1]";
sqlDataAdapter1.Fill(dataSet1,"table2");
DataRelation myDr = new DataRelation("myRelation",dataSet1.Tables[0].Columns["ID"],dataSet1.Tables[1].Columns["ID"]);
dataSet1.Relations.Add(myDr);
dataGrid1.DataSource = dataSet1.DefaultViewManager;
dataGrid1.DataMember = "table1";
***********************************************************************
1)What i need is to display the parent tables record( one field) in a text box when its selected , i.e when the child records are displayed.
and
2)Allow the users to make changes to both these tables and Update them ensuring that updated information is valid (basic validation).
guess i need an update method when a 'save changes' button is clicked .
but what do i need to do in the update method to save changes and how to display that field when that record is selected?
thanks,
Jz
2) It is better to use two different data adapters to fill the data. Then you can also use the same adapters with their Update methods to update the data. The adapter will automatically decide which records have to be updated, which are new and which are deleted.
I don't know if you created your data adapter with the designer or manually. If with the designer, just create another one for the second table and don't set the CommandText in the code manually. If you created it manually, you have to create the other one also manually. Use the SqlCommandBuilder (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlcommandbuilderclasstopic.asp) for that, so that all commands are created.