Friday, March 9, 2012

How to call a stored procedure using C#

I have a stored procedure I created in SQL server 2005. Now I need to call the stored procedure in C#. Can someone help me out here? What is the C# code I need to call this stored procedure? I have never done this before and need some help.


CREATE PROCEDURE [dbo].[MarketCreate]

(
@.MarketCode nvarchar(20),
@.MarketName nvarchar(100),
@.LastUpdateDate nvarchar(2),
)

AS
INSERT INTO Market
(
MarketCode
MarketName
LastUpdateDate
)
VALUES
(
@.MarketCode
@.MarketName
@.LastUpdateDate

)

(1) You need to modify your proc according to what I had suggested in my reply to your previous post.

(2) There are plenty of tutorials on the net, including this website where you can get information that you are asking. I just googled for you and here's the first link that came up (and it took me less than a minute):http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx

|||

just the same as you do with normalinline queries.

Instead of command type as text, now you include as stored procedure.

Also in the comamnd text just give the stored procedure name and bind the corresponding parameters .

the below query will be much useful

http://www.c-sharpcorner.com/UploadFile/dclark/InsOutsinCS11302005072332AM/InsOutsinCS.aspx

|||

I have made progress but don't know the command to execute the stored procedure. The stored procedure will insert values into a table. So, do I just call the open method of mySqlCommand object, after using "Parameters.Add(" ") to load my values into the stored procedure call? I noticed that another call is "ExecuteNonQuery();" but this is for a call to a stored proc that does a select statement as opposed to one that enters data into the database.

|||

What ever may the stored procedures used for rither insert or select the method is the same.

you can use execute non query for stored procedure

|||

Refer to this thread on how to call stored procedure with c#http://forums.asp.net/t/1152146.aspx

No comments:

Post a Comment