as you say you have two tables....
so you have to fire insert query in primary key table first and get a identity value means newly added records primary key and then after completion of that process you have to fire second insert query with inserting a value in the FOREIGN key that is the out putted primary key from the first insert query...
IF YOU USE A STORE PROCEDURE THEN USE QUERY LIKE THIS....
INSERT INTO "FIRSTTABLE" (YOUR COLUMN LIST) VALUES (VALUES TO BE INSERTED)
DECLARE @IDENTITY INT
INSERT INTO TABLE1(USERNAME,PASSWORD) VALUES ('test','test')
SELECT @IDENTITY = @@IDENTITY FROM TABLE1
INSERT INTO TABLE2(USERID,FIRSTNAME,LASTNAME,MOBILENO) VALUES (@IDENTITY,'test','test','xxxx')
SELECT * FROM TABLE1
SELECT * FROM TABLE2
OR IF YOU NOT USE A STORE PROCEDURE AND USE ONLY TEXT QUERY THEN USE THIS...
INSERT INTO USERDETAIL(USERNAME,PASSWORD) VALUES ('test','test')
SELECT TOP 1 ID FROM USERDETAIL ORDER BY ID DESC
SELECT MAX(ID) FROM USERDETAIL
INSERT INTO USERPERSONALDETAIL(USERID,FIRSTNAME,LASTNAME,MOBILENO) VALUES ('your select query data','test','test','xxxx')
you have to tack care of relation ship while using parent child relation in database...
you got that error because of that reason....