0

我有一个 Oracle 过程,我必须将一个日期时间值从我分配为 bdp1 的基本日期选择器传递给它。如何从 VB.net 传递这个值。当我通过日期时,它不会执行该功能

Public 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 sqlConnection As OracleClient.OracleConnection = New OracleClient.OracleConnection(connectionString)


    Dim queryString As String = "select * from abc where tran_dttm <= to_date( ':bdp1','MM-DD-YYYY' ) and tran_dttm > to_date( ':bdp1','MM-DD-YYYY')"


    Dim sqlCommand As OracleClient.OracleCommand = New OracleClient.OracleCommand(queryString, sqlConnection)
    sqlCommand.CommandTimeout = 0


    sqlCommand.Parameters.AddWithValue(":strMaterial", txtMaterial.Text)
    sqlCommand.Parameters.AddWithValue(":ListBox1", ListBox1)
    sqlCommand.Parameters.AddWithValue(":bdp1", bdp1)



    Dim dataAdapter As OracleClient.OracleDataAdapter = New OracleClient.OracleDataAdapter(sqlCommand)
    Dim dataSet As DataSet = New DataSet
    dataAdapter.Fill(dataSet)

    Return dataSet

End Function
4

1 回答 1

0

1)将其作为日期传递,而不是您随后将其转换为数据库中日期的字符串。那是疯狂的谈话。

2) 如果你真的想这样做,那么你不能引用你的参数:to_date( ':bdp1','MM-DD-YYYY' )它正在尝试 to_date 文字字符串':bdp1'。将其更改为:to_date( :bdp1,'MM-DD-YYYY' )

编辑

糟糕,我误读了您的代码,当我看到您的 to_date 内容时,我以为您正在传递一个字符串。你实际上是在传递一个日期,所以你根本不需要调用 to_date。你应该能够做到这一点:

select * from abc where tran_dttm <= :bdp1 and tran_dttm > :bdp1

同样,请注意,您不会将参数包含在单引号中。

于 2013-06-06T03:26:51.417 回答