468,133 Members | 1,167 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Executing a Stored Procedure using Command Text

I urgently need help on how to execute a stored procedure in SQL Express 2005. I have created a stored procedure with as follows:

Create Procedure upInsertCountry

@CountryName varchar(50)

INSERT INTO CountryTable (CountryName) VALUES (@CountryName)

When run the following code :

myCom.CommandType.StoredProcedure
myCom.CommandText = "upInsertCountry @CountryName = 'South Africa' "

I get the error message 'Incorrect Syntax near 'upInsertCountry'

But when i copy the above statement and run it in the Management Studio, it works.

I am using SQL Express 2005
Any idea what the problem is?
Sep 8 '07 #1
2 6551
You have the wrong CommandText for the CommandType of StoredProcedure.
You should be simply setting CommandText = to the stored procedure name, and set the parameters in the parameters collection of the command object.

An alternative, however less desired method of executing would be to execute the procedure as CommandType.Text. Then you could execute with the CommandText set as such:

Expand|Select|Wrap|Line Numbers
  1. exec upInsertCountry @CountryName = 'South Africa' 

http://forums.microsoft.com/MSDN/Sho...89684&SiteID=1
Oct 5 '07 #2
debasisdas
8,127 Expert 4TB
Find the details of calling stored procudure here and modify as required including the connection string.
Oct 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Dino L. | last post: by
4 posts views Thread by Stuart Ferguson | last post: by
reply views Thread by pompeyoc | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.