why doesn't NewRow doesn't create child rows

why doesn't NewRow doesn't create child rows

Post by Matthew D. Langsto » Sun, 06 Oct 2002 02:08:57



I have a typed dataset with two tables in a parent/child relationship. When
I create a new row in the table with the foreign key and then try to access
the corresponding row, ADO.NET throws a NullReferenceException with the
message "Object reference not set to an instance of an object". Here is a
simple example demonstrating the problem (the NullReferenceException is
thrown when I try to set the gAe property):

Dim oFitConfigurationsDataSet As New FitConfigurationsDataSet()
oFitConfigurationsRow =
oFitConfigurationsDataSet.FitConfigurations.NewFitConfigurationsRow
oFitConfigurationsRow.FitParametersRow.gAe = 42.314

I also tried creating the subordinate row explicitly as follows, but this
didn't change anything and the NullReferenceException is still thrown when I
try to set the gAe property:

Dim oFitConfigurationsDataSet As New FitConfigurationsDataSet()
oFitConfigurationsRow =
oFitConfigurationsDataSet.FitConfigurations.NewFitConfigurationsRow
oFitConfigurationsRow.FitParametersRow =
oFitConfigurationsDataSet.FitParameters.NewFitParametersRow
oFitConfigurationsRow.FitParametersRow.gAe = 42.314

Clearly I am missing something pretty basic about using DataSets with
multiple tables related with foreign keys. I expected  NewRow to "cascade"
through the DataSet and create the subordinate row in the related table, but
it doesn't? Would someone please tell me how to create a new row such that
subordinate rows are created as well? Thank you.

Warmest regards, Matt

--
Matthew D. Langston
SLD, Stanford Linear Accelerator Center

 
 
 

why doesn't NewRow doesn't create child rows

Post by Malcolm Stewa » Tue, 08 Oct 2002 23:29:17


Matt,

<<
I have a typed dataset with two tables in a parent/child relationship. When
I create a new row in the table with the foreign key and then try to access
the corresponding row, ADO.NET throws a NullReferenceException with the
message "Object reference not set to an instance of an object". Here is a
simple example demonstrating the problem (the NullReferenceException is
thrown when I try to set the gAe property):
..
Clearly I am missing something pretty basic about using DataSets with
multiple tables related with foreign keys. I expected  NewRow to "cascade"
through the DataSet and create the subordinate row in the related table, but
it doesn't? Would someone please tell me how to create a new row such that
subordinate rows are created as well? Thank you.

The hierarchical relation only exisits when the DataRow is part of a
DataSet. Your code creates a free row. As such, it has no access to parent
or child rows. In addition, you also have to explicitly add child rows;
they are not implicitly created for you.

Malcolm Stewart
Microsoft Developer Support
This posting is provided "AS IS", with no warranties, and confers no rights.

Are you secure?  For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.