-1

你好我正在使用 oracle & vb.net

这是我的选择语句代码,我想从我使用基本日期选择器的界面中显示选定的日期,并将其分配为 bdp1

 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')and lpt = '" & ListBox1 & "' and device = '" & strMaterial & "')"
4

2 回答 2

1

select * from abc where trunc (tran_dttm) = to_date('" & bdp1 & "','MM/DD/YYYY')

于 2013-07-12T01:37:46.663 回答
0

参数应以 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 属性作为参数的值(尽管需要进行一些错误检查)

于 2013-06-10T08:29:00.363 回答