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

Re: C#, Stored Procedure and Parameter by Miha

Miha
Sat Dec 20 06:47:03 CST 2003

Hi Peter,

Set command.CommandType to CommandType.StoredProcedure..

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

"Peter" <anonymous@discussions.microsoft.com> wrote in message
news:07e701c3c6f6$8a167d50$a101280a@phx.gbl...
> 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