how to use Store Procedure in VC# 2005 and SQL 2005 ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi
i want to use Store Procedure for Insert,Update and Delete operation in my
c# app, but how to do ??
please give me an example,source or article or ...
thanks
 
Hi hamed,

first of all, you have to create the stored procedures on your sql-server
with help of query analyser:

CREATE PROCEDURE your_insert_sp
(@field1 [int],
@field2 [nvarchar](15)

AS INSERT INTO Categories
( [field1],
[field2]

VALUES
(@field1,
@field2
GO




to use these stored procedured in c# you can do the following:

SqlConnection con = new SqlConnection(<your constring>);
con.Open();
SqlCommand cmd = new SqlCommand("your_insert_sp", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteScalar();
con.Close();


hope it helps

marcel beutner


PS: the parameters @field1 and @field2 must define in the
SqlParameterCollection of your command object
 
hi

Did you google this question?

There are examples all over the internet of how to use SP in C#
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top