Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 3-Apr-12 21:42pm
v2

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
C#
DataClassesDataContext Db = new DataClassesDataContext();

then call your procedure
C#
Db.usp_insertIntotest(txtName.Text);


Best regards
M.Mitwalli
 
Share this answer
 
Comments
deepakaitr12345 4-Apr-12 4:04am    
Don't forget to drag and drop the Sp to your DBML file,otherwise you won't get the stored procedure name

Thanks
Mohamed Mitwalli 4-Apr-12 7:23am    
Yes you are right i forget to mention it thanks
super_user 19-Oct-16 7:40am    
how to add where condition
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".
C#
private TenderManagementDataContext __dataConnection = null;
__dataConnection = new TenderManagementDataContext();

__dataConnection.AddSiteUser(emailID, username, password);

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

3. Then call your SP with paramaters.
 
Share this answer
 
 
Share this answer
 
I think you need to retive value by using the output parameter that you can check over here : Stored procuedure to retrive data :
A scott gu post which explain that easily [^]
 
Share this answer
 
v3

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