Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Master-Detail insert

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2007-01-21 : 04:57:52
Master table (tlbProduct) having productID as Primary key and
which acts as reference key for table (tlbCategory).
Fields for tlbProduct are productID,productName
Fields for tlbCategort are productID,CategoryID(primary key),CategoryName,Prize
both productID,CategoryID are autoincrementing.
but when i write two inserts simultaneously as follows
insert into tlbProduct(productName)values(@productName)
insert into tlbCategory(CategoryName,Prize)
I get the error that ProductID value is null which is not provided
But (productId in both is autoincremented) and relationship is there in both tables
How to resolve this problem without adding ProductID in second Inser
?
SWati

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-21 : 10:11:14
productId in both is autoincremented
relationship is there in both tables

Are you sure it's not autoincremented in tlbProduct and a foreign key in tlbCategory (sounds a bit of an odd structure - would expect CategoryID to be a foreign key in tlbCategory)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-01-21 : 13:55:13
If you are running SQL Server, both productID and CategoryID cannot be autoincrementing(IDENTITY) in tblCategory, since only IDENTITY column is allowed per table. More that likely, CategoryID, not productId, is the IDENTITY column for tblCategory

You will have to supply the value for ProductID when you insert into tblCategory.






CODO ERGO SUM
Go to Top of Page
   

- Advertisement -