Link to home
Start Free TrialLog in
Avatar of mcain_bba
mcain_bba

asked on

SQL0312: Variable xxx not Defined or Not Usable

Hi,
After writing the code without the aid of wizards, the program is generating the following error message at the DA.Fill(DS, "HPOL01") statement.

SQL0312: Variable PONum not Defined or Not usable

If I hardcode a PO number in the select statement, it works great.  But when I try to pass a parameter, no luck, I just cannot figure it out.  Below, you will find my code.  Any ideas or suggestions will be greatly appreciated.

vb.net
vs.net
db2


Thanks

MC

Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim PONum As Integer
    Dim strConn As String = "Protection Level=None;Data Source=svlprod;Force Translate=65535;User ID=xxxx;Cursor Sensitivity=3;Initial Catalog=CORP;Transport Product=Client Access;Catalog Library List=;Default Collection=xxxx;Persist Security Info=False;Convert Date Time To Char=TRUE;SSL=DEFAULT;Provider=IBMDA400"
    Dim CN As New OleDbConnection(strConn)
    Dim DA As New OleDbDataAdapter
    Dim DS As New DataSet

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        Try
            DS.Clear()
            DA.SelectCommand = New OleDbCommand
            DA.SelectCommand.Connection = CN
            DA.SelectCommand.CommandText = "SELECT PUM, PPROD, PORD, PVEND FROM V810BPCSF.HPOL01 WHERE (PORD = :PONum)"
            DA.SelectCommand.Parameters.Add(":PONum", OleDbType.Integer)
            DA.SelectCommand.Parameters(":PONum").Value = 223988
            CN.Open()
            DA.Fill(DS, "HPOL01")
            DG1.DataSource = (DS)
            DG1.DataMember = ("HPOL01")
            CN.Close()

        Catch ex As Exception
            MsgBox(Err.Description, , Err.Number)
        End Try
    End Sub
    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        End
    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of arif_eqbal
arif_eqbal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcain_bba
mcain_bba

ASKER

YES .... It Works!!!!!

Because I need to pass a parameter, I substituted the field name for the value and it work!  

DA.SelectCommand.CommandText = String.Format("SELECT PUM, PPROD, PORD, PVEND FROM V810BPCSF.HPOL01 WHERE (PORD = {0})", PONum)