Monday, March 19, 2012

how to use parameters in method (filter by parameter)

Hello!

I've begin to do a tutorial of this site: Working with Data in ASP.NET 2.0 c#, but in the 3. step I can't make something:

In this step I can't add parameterized methods to the TableAdapter. The problem come up when I want to add Sql query.

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID = @.CategoryID

The error message:

Error in WHERE clause near'@.'.
Unable to parse query text.

So, how can i use parameter in this method?

tnx for the help

Simpson

Are you sure you are passing in the parameter values to the TableAdapter when calling in your code?

Thanks

|||Hi

I have the same problem have you found a solution.

Regards
Demetrios|||Hi

I have the same problem have you found a solution.

Regards
Demetrios|||Hi

I have the same problem have you found a solution.

Regards
Demetrios|||

Hi MaoBranca,

This might because the @.CategoryID was not declared properly.

If this is a SQL Server database, please make sure that you have added the parameter to the SqlCommand parameter collection. If it has been added, please also confirm that the data type, size and value are correct.

HTH. If this does not answer you question, please feel free to mark it as Not Answered and post your reply. Thanks!

|||i have found the solution

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID = @.CategoryID

this works for sqlserver if you are using an access database then it is

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID = ?

if you are using mysql then it is

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID = #CategoryID

but i an not sure with mysql

No comments:

Post a Comment