Using OLEDB parameters in .NET when connecting to an AS400/DB2

Posted by Jeff Stock on Stack Overflow See other posts from Stack Overflow or by Jeff Stock
Published on 2010-03-24T21:10:48Z Indexed on 2010/03/24 21:13 UTC
Read the original article Hit count: 832

Filed under:
|
|
|
|

I have been pulling my hair out trying to figure out what I can't get parameters to work in my query. I have the code written in VB.NET trying to do a query to an AS/400. I have IBM Access for Windows installed and I am able to get queries to work, just not with parameters. Any time I include a parameter in my query (ex. @MyParm) it doesn't work. It's like it doesn't replace the parameter with the value it should be. Here's my code:

I get the following error: SQL0206: Column @MyParm not in specified tables

Here's my code:

Dim da As New OleDbDataAdapter
Dim dt As New DataTable

da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = con

da.SelectCommand.CommandText = "SELECT * FROM MyTable WHERE Col1 = @MyParm"
With da.SelectCommand.Parameters
   .Add("@MyParm", OleDbType.Integer, 9)
   .Item("@MyParm").Value = 5
End With

' I get the error here of course
da.Fill(dt)

I can replace @MyParm with a literal of 5 and it works fine. What am I missing here? I do this with SQL Server all the time, but this is the first time I am attempting it on an AS400.

© Stack Overflow or respective owner

Related posts about as400

Related posts about sql