我有兩個值的日期格式爲dd/MM/yyyy,並且試圖獲取這兩個值之間的日期。這些值在一個和兩個變量中看起來像這些(17/06/2013)。然後我從asp發送到oracle程序來執行查詢,並且我得到的ORA-01843不是一個有效的月份。我找到了這個錯誤,但沒有一個解決方案似乎爲我工作。問題在於,這段代碼曾經工作過,我沒有改變這些代碼上的任何東西,現在它由於某種原因不起作用。不是一個有效的月份asp.net/oracle
這裏是我的ASP代碼:
ONE = fromDate.Value
TWO = toDate.Value
Generic.searchBetweenDates(ONE, TWO, dt)
Public Function searchBetweenDates(ByVal PFROMDATE As String, ByVal PTODATE As String, ByRef PUSERINFO As DataTable)
Dim myDataTable As New DataTable
Dim myDataAdapter As New OracleDataAdapter
Dim oraCmd As New OracleCommand("cantine_test.searchbetweendates")
oraCmd.CommandType = System.Data.CommandType.StoredProcedure
oraCmd.Parameters.Add(New OracleParameter("PFROMDATE", OracleType.VarChar, 30)).Value = PFROMDATE
oraCmd.Parameters.Add(New OracleParameter("PTODATE", OracleType.VarChar, 300)).Value = PTODATE
oraCmd.Parameters.Add(New OracleParameter("PUSERINFO", OracleType.Cursor)).Direction = ParameterDirection.Output
Dim oConn As New OracleConnection(ConnectionString)
Try
oConn.Open()
oraCmd.Connection = oConn
cleanParams(oraCmd.Parameters)
myDataAdapter.SelectCommand = oraCmd
myDataAdapter.Fill(myDataTable)
If Not myDataTable Is Nothing Then
PUSERINFO = myDataTable 'return reference using byref param
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
oraCmd.Dispose()
oConn.Close()
myDataAdapter.Dispose()
End Try
Return PUSERINFO
End Function
這裏是從我的Oracle過程代碼:
PROCEDURE searchbetweendates
(PFROMDATE IN VARCHAR2, PTODATE IN VARCHAR2, PUSERINFO OUT SYS_REFCURSOR)
AS
BEGIN
OPEN PUSERINFO FOR
SELECT ORDERDATE,ORDERID,ORDERTIME,ORDERLIST,QUANTITY,ITEMPRICE,ORDERPRICE,LOCATION
FROM ORDERSDETAIL
WHERE ORDERDATE >= to_date(PFROMDATE, 'dd/MM/yyyy')
AND ORDERDATE <= to_date(PTODATE,'dd/MM/yyyy');
END;
任何想法?
您確定fromDate.Value會以正確的格式爲您提供日期嗎?調試並檢查傳遞給Oracle的字符串格式。 – GTG
還有一件奇怪的事情。 Generic.searchBetweenDates(fromDate.Value,toDate.Value,dt)這給了我一個不同的格式'#6/17/2013#{Date}'當它到達另一個類時:Public Function searchBetweenDates(ByVal PFROMDATE As String ,ByVal PTODATE As String,ByRef PUSERINFO As DataTable)PFROMDATE和PTODATE具有正確的值,如'17/06/2013'。我嘗試從Date.Value和ONE兩者發送,並修改了我的過程,但結果仍然相同。 –