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

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

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.


You're right, same question as AS400 SQL query with Parameter, which contains the solution.

Just a note: Host Integration Server 2006 supports named parameters.

Need Your Help

How can I write list type returning value in Linq with Entity Framework?

c# .net visual-studio-2008 c#-4.0

How can I return List<personel> data type from below procedure. If I press F5 it throw me this error:

MFP 7.1 issue with ChallengeHandler when expirationInSeconds is reached

ibm-mobilefirst worklight-security mobilefirst-server

I was testing device SSO and wanted to see what happens when the session has expired on the server side. Therefore I have added a expirationInSeconds to my LoginModule and now once the timeout has ...