C#, Stored Procedure and Parameter

P

Peter

Hi, I have a bug defined as below:
* Northwind database, Customers table
create a procedure GetCompanyName as below:
ALTER PROCEDURE GetCompanyName @CustomerID nchar(5)
AS
SELECT CompanyName
FROM Customers
WHERE CustomerID = @CustomerID
The procedure has been tested with right result.
* The corsponding C# code is as below:
string cn = ....;
SqlConnection connection = new SqlConnection(cn);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "GetCompanyName";
command.Parameters.Add("@CustomerID", "ALFKI");//needed

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
adapter.TableMappings.Add("Table", "Customers");
DataSet ds = new DataSet();
adapter.Fill(ds);
* The purpose is to demonstrate to use line 5.
* When I ran it, I got an exception. The message is "Line
1: Incorrect syntax near GetCompanyName".
Please advice.
Peter
 

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

Top