如何插入引用 [英] how to insert into references

查看:102
本文介绍了如何插入引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

家伙我不知道为什么我在谷歌找不到这个答案对我来说似乎很常见!!!

我的问题是当你有两个表时,一个是[tblemployee],第二个是[tbldeparment]
$ [bblemployee]中的b $ b我们有

 < u> ID  名称  Depid  * depid是tbldepart的参考* 
1 john 2
2 sam 1

[bbdedepart]
我们有

<前lang =text> ID Depname
1 IT
2 cctv

因此当我制作c#应用程序时,用户不会知道(1代表IT,2代表中央电视台)

 sqlcommand cmd =  new  sqlcommand( 插入到tblemployee(name,depid)值(@ name,@ depid)); 



它将非常感谢任何类型的答案,

如果我的问题不清楚我会道歉

解决方

好吧,你可以尝试:

  INSERT   INTO  tblEmployee(EmpName,DepId) VALUES  @ NAME ,(< span class =code-keyword> SELECT  ID  FROM  tblDepart a  WHERE  a.DepName =  @ DEPID ))


感谢您的回答,,,

好​​吧让我尝试让它更清楚,如果我可以,,,

当我尝试向tblemployee插入行时我应该插入这样的值

  insert   into  tblemployee(name,depid)'  john' 2 



但我想要插入值这个

 插入 进入 tblemployee( name,depid) values '  john''  cctv'



因为我不会每次都知道2对于中央电视台来说....

非常感谢


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)

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

解决方案

Well, you could try:

INSERT INTO tblEmployee (EmpName, DepId) VALUES (@NAME, (SELECT ID FROM tblDepart a WHERE a.DepName = @DEPID))


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

insert into tblemployee (name,depid) values ('john',2)


but i want insert value like this

insert into tblemployee (name,depid) values ('john','cctv')


because i won't know that 2 is for cctv every time ....
thanks a lot


这篇关于如何插入引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆