Click here to Skip to main content
16,017,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a table Client having fields Id int,name varchar,address varchar
& have created stored procedure as below:
SQL
create procedure ClientInsert
@id int,
@name varchar(50),
@address varchar(100)
as
insert into Client (ID,Name,Address)values(@id,@name,@address).

The thing is that I want to insert the values using Linq in the table using stored procedure.
Please let me know how to implement.
Posted
Updated 26-Oct-10 2:12am
v2

Per your last comment...

You would need to capture the value from the textbox and pass it through to the stored proc via the data context. Something similar to this:

string clientName = txtClientName.Text;
string clientAddress = txtClientAddress.Text;

YourDataContext dc = new YourDataContext();
dc.ClientInsert(yourId, clientName, clientAddress);


Again, I would not generate an ID client side, I would return it from the stored proc, so I would prefer to see this:

string clientName = txtClientName.Text;
string clientAddress = txtClientAddress.Text;
int? clientID = 0;
YourDataContext dc = new YourDataContext();
dc.ClientInsert(ref clientID, clientName, clientAddress);


Edited to fix second approach...

Cheers.
 
Share this answer
 
v2
Comments
Mohd Wasif 28-Oct-10 2:17am    
Thank U
You can check this thread.

Stored Procedure in Linq to Sql Server[^]
 
Share this answer
 
If you're using LINQ to SQL, you can drag the stored proc from the Server Explorer tool window onto your DBML diagram.

The stored proc will then be available through your Data Context.

You would likely want to return SCOPE_IDENTITY as well, so that the calling code would be able to know what the generated ID was of the record you've just inserted.

Cheers.
 
Share this answer
 
Comments
Mohd Wasif 26-Oct-10 8:30am    
Dear I have done all that but i need how to use through controls suppose if i m passing all the values through textbox and what would be linq query on button click.

thank u.
TheyCallMeMrJames 26-Oct-10 8:37am    
Dear? Heheh...friendly! I'll post some pseudo code...

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