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;Prov ider=IBMDA 400"
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.Connectio n = CN
DA.SelectCommand.CommandTe xt = "SELECT PUM, PPROD, PORD, PVEND FROM V810BPCSF.HPOL01 WHERE (PORD = :PONum)"
DA.SelectCommand.Parameter s.Add(":PO Num", OleDbType.Integer)
DA.SelectCommand.Parameter s(":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
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;Prov
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.Connectio
DA.SelectCommand.CommandTe
DA.SelectCommand.Parameter
DA.SelectCommand.Parameter
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because I need to pass a parameter, I substituted the field name for the value and it work!
DA.SelectCommand.CommandTe