T
tmeynink
Hi,
In ADO.NET 2.0 if you have a table with foreign keys in it, when you
add a row using the strongly typed add row method you pass references
to the foreign rows rather than the foreign key value itself.
If any of these foreign key row references are null, I get an
exception.
The only way I have found to work around this is to use the following
for each column with a foreign key that can be null:
TypedDataSet.SomeTableRow myNewRow = ds.SomeTable.NewSomeTableRow ();
TypedDataSet.ForeignTableRow foreignRow = ds.ForeignTable.FindByID
(id);
//
// repeat for each foreign key column that allows nulls...
//
if (null != foreignRow)
{
myNewRow.ForeignKeyID = foreignRow.ID;
}
else
{
myNewRow["ForeignKeyID"] = DBNull.Value;
}
ds.SomeTable.AddSomeTableRow (myNewRow);
I must be missing something here - surely the generated code is smart
enough to detect null values for foreign key references and insert a
DBNull.Value in the appropriate foreign key columns (where null values
are allowed of course).
What am I missing here?
Thanks,
Todd
In ADO.NET 2.0 if you have a table with foreign keys in it, when you
add a row using the strongly typed add row method you pass references
to the foreign rows rather than the foreign key value itself.
If any of these foreign key row references are null, I get an
exception.
The only way I have found to work around this is to use the following
for each column with a foreign key that can be null:
TypedDataSet.SomeTableRow myNewRow = ds.SomeTable.NewSomeTableRow ();
TypedDataSet.ForeignTableRow foreignRow = ds.ForeignTable.FindByID
(id);
//
// repeat for each foreign key column that allows nulls...
//
if (null != foreignRow)
{
myNewRow.ForeignKeyID = foreignRow.ID;
}
else
{
myNewRow["ForeignKeyID"] = DBNull.Value;
}
ds.SomeTable.AddSomeTableRow (myNewRow);
I must be missing something here - surely the generated code is smart
enough to detect null values for foreign key references and insert a
DBNull.Value in the appropriate foreign key columns (where null values
are allowed of course).
What am I missing here?
Thanks,
Todd