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.mydb.Hotel_Details_Lang'; column does not allow nulls. INSERT
fails." Any idea?
PS: To create the DataAdapters, I'm using SqlCommandBuilder.
public void Insert_Hotel_Details(string hdtDescription) {
DataSet dsTemp = null;
try {
// Get the dataset with those two tables to use;
dsTemp = Get_Hotel_Details();
//Parent Table;
DataRow drwParent = dsTemp.Tables["Hotel_Details"].NewRow();
drwParent["hdtTemp"] = false;
dsTemp.Tables["Hotel_Details"].Rows.Add(drwParent);
//Child Table;
DataRow drwChild = dsTemp.Tables["Hotel_Details_Lang"].NewRow();
drwChild.SetParentRow(drwParent);
drwChild["lngID"] = 1;
drwChild["hdtDescription"] = hdtDescription;
dsTemp.Tables["Hotel_Details_Lang"].Rows.Add(drwChild);
daHotel_Details.Update(dsTemp);
daHotel_Details_Lang.Update(dsTemp);
}
catch (System.Exception EErr) {
throw new Exception(EErr.Message, EErr);
}
finally {
if (dsTemp != null) dsTemp.Dispose(); dsTemp = null;
}
}
Thanks in advance.
--
Fabio Negri Cicotti
Software Engineer