Hi All.
I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's
SetParentRow method. The parent table has an identity column as primary key.
When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.myd b.Hotel_Details _Lang'; column does not allow nulls. INSERT
fails." Any idea?
PS: To create the DataAdapters, I'm using SqlCommandBuild er.
public void Insert_Hotel_De tails(string hdtDescription) {
DataSet dsTemp = null;
try {
// Get the dataset with those two tables to use;
dsTemp = Get_Hotel_Detai ls();
//Parent Table;
DataRow drwParent = dsTemp.Tables["Hotel_Deta ils"].NewRow();
drwParent["hdtTemp"] = false;
dsTemp.Tables["Hotel_Deta ils"].Rows.Add(drwPa rent);
//Child Table;
DataRow drwChild = dsTemp.Tables["Hotel_Details_ Lang"].NewRow();
drwChild.SetPar entRow(drwParen t);
drwChild["lngID"] = 1;
drwChild["hdtDescription "] = hdtDescription;
dsTemp.Tables["Hotel_Details_ Lang"].Rows.Add(drwCh ild);
daHotel_Details .Update(dsTemp) ;
daHotel_Details _Lang.Update(ds Temp);
}
catch (System.Excepti on EErr) {
throw new Exception(EErr. Message, EErr);
}
finally {
if (dsTemp != null) dsTemp.Dispose( ); dsTemp = null;
}
}
Thanks in advance.
--
Fabio Negri Cicotti
Software Engineer