Parameter issues in VB.NET for AS/400

56,485 pts.
Tags:
AS/400
queries
SQL Server
I am having problems getting parameters to work within a VB.NET query written to AS/400. Any time I include a parameter in my query (ex. @MyParm) it doesn't work. 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
da.Fill(dt)
It does work fine if I  replace @MyParm with a literal of 5. What am I missing here?

ASKED: December 24, 2013  2:48 PM
UPDATED: December 24, 2013  2:51 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta

    I'm not an expert in VB.NEt, but Microsoft OleDbCommand.Parameters Property documentation says:

    • The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used.

    You appear to be declaring your command as Text (i.e., CommandText). Try restructuring similar to the example in the documentation.

    Tom

    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following