在ASP.net C#中使用Linq调用StoreProcedure [英] Calling a StoreProcedure using Linq in ASP.net C#

查看:80
本文介绍了在ASP.net C#中使用Linq调用StoreProcedure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在做一个项目,需要使用Linq中的存储过程将数据插入数据库.我在Linq类中得到存储过程名称.存储过程用于将数据插入DB.所以现在我的问题是我该如何调用存储过程并将参数从表示层传递到该过程然后执行它.我在互联网上搜索后得到一个结果,说我需要创建一个视图,但我没有得到它.因此,谁能说出如何使用Linq传递参数来存储过程并执行它.发送一些建议或链接会对我有所帮助..

预先感谢
Arun

Hello every one

I am doing a project where i need to insert data into DB using Store Procedure in Linq. I am getting the store procedure name in Linq class . The store procedure is used for inserting a data into DB. So now my problem is How can i call that Store Procedure and pass parameter into that procedure from presentation layer and then execute it .I search in internet it gave me a result saying that I need to create a view , but i am not getting it . So can anybody tell how to pass parameter to store procedure using Linq and execute it . Send some suggestions or link which will help me ..

Advance Thanks from
Arun

推荐答案


您必须首先创建DataClassesDataContext,然后您必须映射您的存储过程并保存DBML文件.然后从您的上下文中获取对象.
创建DataClassesDataContext添加新项目,然后选择LinQ到SQL类
Hi ,
you have to create first DataClassesDataContext then u have to map your stored procedure and save the DBML file . then take object from your context .
to create DataClassesDataContext add new item then choose LinQ to SQL Classes
DataClassesDataContext Db = new DataClassesDataContext();


然后调用您的程序


then call your procedure

Db.usp_insertIntotest(txtName.Text);



最好的问候
M.Mitwalli



Best regards
M.Mitwalli


1.如果您使用的是LINQ,我想您还可以使用"LINQ to SQL"类进行映射.然后将表和SP拖放到"LINQ to SQL"中.
1. If your using LINQ , i think you also use "LINQ to SQL" class for mapping. then drag drop your tables and SP in "LINQ to SQL".
private TenderManagementDataContext __dataConnection = null;
__dataConnection = new TenderManagementDataContext();

__dataConnection.AddSiteUser(emailID, username, password);


2.在要调用SP的地方创建"LINQ to SQL"类的对象.

3.然后使用参数调用您的SP.


2. Create object of "LINQ to SQL" class where you want to call SP.

3. Then call your SP with paramaters.


这可能会对您有所帮助.
[在LINQ中使用存储过程的六个简单步骤]
This may help you.
[Six simple steps to use a Stored Procedure in LINQ]


这篇关于在ASP.net C#中使用Linq调用StoreProcedure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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