-2

I am trying to add a parameter to my table adapter in my C# project. When I add the @ to the where clause visual studio gives me an error. Here is my SQL statement:

select PO.PO_Num,
  PO.Supplier,
  PO.DateOrdered,
  PO.DateRequired,
  PO.Terms,
  PO.Freight,
  PO.FOB,
  POItems.PO_Num as Expr1,
  POItems.Quantity,
  POItems.Description,
  POItems.Item,
  POItems.Price,
  POItems.KeyNum
from PO,
  POItems
where PO.PO_Num = POItems.PO_Num
  and (PO.PO_Num = @PO_Num)

Can someone please tell me what I am doing wrong? Thanks in advance for any help!

Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
nate
  • 1,418
  • 5
  • 34
  • 73
  • 2
    Use a question mark instead of `@PO_Num`. What did you try? Did you search the web for the error message? – CodeCaster Nov 27 '13 at 18:06
  • Duplicate of [How to use named parameters in a TableAdapter query?](http://stackoverflow.com/questions/15270591/getting-error-while-configuring-the-fill-method-of-tableadapter-config-wizard). – CodeCaster Nov 27 '13 at 18:08
  • @CodeCaster I can just add a ? instead of "at symbol" + parameter to create a parameter? And I tried what you see above, since I didn't know what else to try or do. – nate Nov 27 '13 at 18:12
  • _"What have you tried"_ does not mean _"What code do you currently have that doesn't work"_, but it mean _"What have you tried to resolve the issue"_, hence my asking about you searching the web. Parameters for OLEDB are parsed in order, so just `?` will do. – CodeCaster Nov 27 '13 at 18:13
  • @CodeCaster And this is not a duplicate question to the one that you posted. since I am not using access, and I am using SQL. I am also trying to use the "at symbol" to create a parameter, which SQL lets you do. – nate Nov 27 '13 at 18:15
  • It **is** a duplicate. The error is not caused by Access, but by the data access the TableAdapter uses (most likely OLEDB in this case, given the error). – CodeCaster Nov 27 '13 at 18:16

2 Answers2

3

To fix the error I needed to change the where clause from this:

where PO.PO_Num = POItems.PO_Num and (PO.PO_Num = @PO_Num)

And add a question mark (?) in stead of the at symbol (@) like so:

where PO.PO_Num = POItems.PO_Num and (PO.PO_Num = ?)

After that I was able to execute the query, and Visual Studio 2010 didn't throw an error.

nate
  • 1,418
  • 5
  • 34
  • 73
0

I just came across this problem when adding a table adapter and using a data source of .NET framework Data provider for oracle. The two solutions of changing the where clause to use "@" and "?" didn't work for me.

Instead, I had to use the following:

where PO.PO_Num = POItems.PO_Num and (PO.PO_Num = :PO_Num)
Jacob Heck
  • 53
  • 1
  • 7