hi i'm thinking of putting 3 texboxes for the user to enter their previous work exp which look something like this:
experience
First job.textbox
Secondjob.textbox
Thirdjob.textbox
i'm kinda confuse on with the database. The 3 tables required means i will hav 3 sqldatasource ...
which i didin't quite get it right with the Secondjob table.I try using identity_scope() and @.@.identity to get the ID from my first table(personel)
which is autogenerate number. It works fine with Firstjob table but not secondjob table.
Generated error message:
(1 row(s) affected)
(1 row(s) affected)
Msg 547, Level 16, State 0, Line 6
The INSERT statement conflicted with the FOREIGN KEY constraint "Personnel_Secondjob". The conflict occurred in database "test", table "dbo.Personnel", column 'IDPersonnel'.
The statement has been terminated.
INSERTINTO dbo.Personnel
(Name)
VALUES
('Jon')insert
into Firstjob(Designation, Employer, YearWorking, IDPersonnel)values
('Teachier,'Gam','7thn',scope_identity())insert
into Secondjob(Designation, Employer, YearWorking, IDPersonnel)values
('Musician','KKSB','8thn',scope_identity())any suggestions...
Declare @.id1int, @.id 2intINSERT INTO dbo.Personnel (Name)VALUES ('Jon')SELECT @.ID1 = SCOPE_IDENTITY()insert into Firstjob(Designation, Employer, YearWorking, IDPersonnel)values ('Teachier', 'Gam', '7thn', @.ID1) SELECT @.id2 = SCOPE_IDENTITY() insert into Secondjob(Designation, Employer, YearWorking, IDPersonnel) values ('Musician', 'KKSB', '8thn', @.ID2)|||
it generate an error:
Msg 547, Level 16, State 0, Line 9
The INSERT statement conflicted with the FOREIGN KEY constraint "Personnel_PnglmnKerja2". The conflict occurred in database "test", table "dbo.Personnel", column 'IDPersonnel'.
The statement has been terminated.
i changed line 5 to
SELECT @.id2= @.ID1
or reduce the code to
SELECT @.ID1 = SCOPE_IDENTITY()
insert into Firstjob(Designation, Employer, YearWorking, IDPersonnel)values ('Teachier', 'Gam', '7thn', @.ID1)
insert into Secondjob(Designation, Employer, YearWorking, IDPersonnel) values ('Musician', 'KKSB', '8thn', @.ID1)
and it worked... thanx for the idea i'm just beginner,learning mssql through forums & ebook. I really appreciate it
do u foresee any problem if many people try to insert their data concurently?10-20 people at the same time
No comments:
Post a Comment