By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Executing a Stored Procedure using Command Text

P: 2
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.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
Share this Question
Share on Google+
2 Replies

P: 1
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'
Oct 5 '07 #2

Expert 5K+
P: 8,127
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.