参数应以 the 为前缀,:
并且应作为文本直接包含在命令中。框架的工作是将它们及其值传递给数据库引擎
Private Function GetDate(ByVal strMaterial As String, ByVal ListBox1 As String, ByVal bdp1 As Date) As DataSet
Dim connectionString As String = "Data Source = ***; User ID = ***; Password = **;"
Dim queryString As String = "BEGIN select * from abc " & _
"where (tran_dttm <= to_date(:bdp1,'MM/DD/YYYY') and " & _
"tran_dttm > to_date(:bdp1 ,'MM/DD/YYYY') and " & _
"lpt = :lb1 and device = :mat); END;"
Using sqlConnection = New OracleClient.OracleConnection(connectionString)
Using sqlCommand = New OracleClient.OracleCommand(queryString, sqlConnection)
sqlCommand.CommandTimeout = 0
sqlCommand.Parameters.Add(New OracleParameter(":bdp1", OracleType.DateTime)).Value = bdp1
sqlCommand.Parameters.Add(New OracleParameter(":lb1", OracleType.VarChar)).Value = lstBox1.SelectedItem.ToString
sqlCommand.Parameters.Add(New OracleParameter(":mat1", OracleType.VarChar)).Value = strMaterial
Dim dataAdapter As OracleClient.OracleDataAdapter = New OracleClient.OracleDataAdapter(sqlCommand)
Dim dataSet As DataSet = New DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Using
End Using
End Function
如果 ListBox1 是控件,则它是错误的。您应该使用 SelectedItem 属性作为参数的值(尽管需要进行一些错误检查)