使用mvc3中的Storedprocedure将数据插入多个表 [英] Insert data into multiple tables using Storedprocedure in mvc3
问题描述
我创建了3个表,如tblA,tblB,tblC
字段是
tblA:
CharityId(PK)名称EmailId CategryId( FK)
1 abc abc@gmail.com 1
2 lmn lmn@gmail.com 1
3 pqr ssd@gmail.com 2
4 abc sss@gmail.com 3
tblB:
CategoryId(PK)名称
1 cat1
2 ca2
3 ca3
4 cat4
tblC:
CharityId(FK )分类(FK)
1 1
1 2
2 1
2 2
2 3
当我想从视图插入数据时,我想用于插入多个表格,如上面的charityid和categoryid插入到单独的像tblC这样的表。
如何通过将MVC3与edm(存储过程)一起使用来实现这一点。
我搜索了很多网站,但没人能解决这个问题。
所以请提供解决方案
I have created 3 tables like tblA, tblB, tblC
field are
tblA:
CharityId(PK) Name EmailId CategryId(FK)
1 abc abc@gmail.com 1
2 lmn lmn@gmail.com 1
3 pqr ssd@gmail.com 2
4 abc sss@gmail.com 3
tblB:
CategoryId(PK) Name
1 cat1
2 ca2
3 ca3
4 cat4
tblC:
CharityId(FK) CategryId(FK)
1 1
1 2
2 1
2 2
2 3
My intention is i when i want to insert data from view that will inserted to more than one tables like above and charityid and categoryid inserted into separate table like tblC.
How can i do this by using MVC3 with edm(stored procedures).
I have searched so many sites but no one can resolve this.
so please provide solution
推荐答案
在您自己的SP中,您可以将数据插入3个表格...
请遵循以下语法。
Hi,
In your SP itself you can insert data into 3 tables...
please follow the below syntax.
CREATE PROCEDURE XXXX
(
@Trans_Type VARCHAR(100),
--add your parameters---
)
AS
BEGIN
IF @Trans_Type='INSERT-A'
---- INSERT DATA INTO tblA
ELSE IF @Trans_Type='INSERT-B'
---- INSERT DATA INTO tblB
ELSE IF @Trans_Type='INSERT-C'
---- INSERT DATA INTO tblC
END
you也可以这样做....
我认为这对你有用......
you can do like this also....
I think it might be help for you....
这篇关于使用mvc3中的Storedprocedure将数据插入多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!