How do I get the IDENTITY field from the d/b?
Posted on 2001-08-10
I am developing a master/detail window. Master refers to a table Amaster and the detail datawindow refers to Adetail table. These two tables have a one-2-many relationship, on a column named m_id, which is an identity column (autonumbered) in table Amaster.
When I insert data in the master datawindow in my app, since the m_id field is not given (it is autonumbered, so SQL Server will give it a number when I commit changes to the d/b), when I try to add data into my detail datawindow and save everything, it tells me that cannot insert NULL value into the m_id field of the Adetail table.
The problem is that since m_id hasn't got a value yet from the Amaster table, when inserting data to the Adetail, it hasn't got the m_id in order to pass it in the INSERT INTO Adetail (...) VALUES (...)
Any help on how to get the m_id before entering data into my detail datawindow, so that it avoids giving me the NULL error?
Or any well known implementation fixes for this problem?