Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone ...
guys i don't know why i couldn't find this answer in the google for me it seems so common!!!
my question is when you have two table one is [tblemployee] and second is [tbldeparment]
in[tblemployee] we have
ID   Name   Depid *depid is reference of tbldepart*
 1   john    2
 2   sam     1

in [tbldepart] we have
ID   Depname
 1     IT
 2    cctv
so when i make c# application the user wouldn't know is(1 is for IT and 2 isfor cctv)
C#
sqlcommand cmd=new sqlcommand ("insert into tblemployee (name,depid)values (@name,@depid)");

it will be so appreciated any type of answer ,,
and i apologies if my question is not be clear
Posted
Updated 15-Apr-15 11:19am
v2
Comments
Joan Magnet 15-Apr-15 14:37pm    
can you redefine the question? it's not really clear.

Well, you could try:
SQL
INSERT INTO tblEmployee (EmpName, DepId) VALUES (@NAME, (SELECT ID FROM tblDepart a WHERE a.DepName = @DEPID))
 
Share this answer
 
thank you for your answers,,,
okay let me try make it more clear if i could ,,,
when i try to to insert row to tblemployee i should insert values like this
SQL
insert into tblemployee (name,depid) values ('john',2)

but i want insert value like this
SQL
insert into tblemployee (name,depid) values ('john','cctv')

because i won't know that 2 is for cctv every time ....
thanks a lot
 
Share this answer
 
Comments
Sascha Lefèvre 15-Apr-15 18:43pm    
This is not a solution. And the author of the actual solution didn't get a notification about it. Please
- add this to your original question
- use the "Have a Question or Comment?"-button below solution 1 to leave him a comment
- delete this not-solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900