我有一个Oracle程序,我必须从基本日期选择器传递一个日期时间值,我将其指定为bdp1。 如何从VB.net传递此值。 当我通过日期时,它的doest执行函数
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
答案 0 :(得分:0)
1)将其作为日期传递,而不是随后CONVERT到数据库中的日期的字符串。这是一个疯狂的谈话。
2)如果您真的想这样做,那么您就无法引用您的参数:to_date( ':bdp1','MM-DD-YYYY' )
它正在尝试更改文字字符串&#39;:bdp1&#39;。将其更改为:to_date( :bdp1,'MM-DD-YYYY' )
修改强> 的
哎呀,我误读了你的代码,当我看到你的to_date时,我以为你传了一个字符串。您实际上已经过了日期,所以您根本不需要调用to_date。你应该能够做到这一点:
select * from abc where tran_dttm <= :bdp1 and tran_dttm > :bdp1
再次注意,您不会将参数包含在单引号中。