转换为oracledbtype.tate到迄今为止是无效的



我正在尝试从OracleCommand.Parameter进行以下操作:

存储过程:

PROCEDURE GetDate(inParam IN VARCHAR2, outDate OUT DATE) AS
    BEGIN
        SELECT MAX(DateVal) INTO outDate
        FROM Table1
        WHERE Col1 = inParam;
    EXCEPTION 
        WHEN no_data_found THEN
        outDate:= NULL;
END GetDate;
Dim returnDate as Date?
Using Connection = New OracleConnection(connectionString)
Using Command As OracleCommand = Connection.CreateCommand()
Connection.Open()
Command.CommandType = CommandType.StoredProcedure
Command.CommandText = "GEN_PACKAGE.GetDate"
Command.Parameters.Add("inParam", inParam).Direction = ParameterDirection.Input
Command.Parameters.Add("outDate", OracleDbType.Date).Direction = ParameterDirection.Output
Command.ExecuteNonQuery()
If Not CType(Command.Parameters("outDate").Value, INullable).IsNull Then
    returnDate = CDate(Command.Parameters("outDate").Value)
End If
End Using
End Using

但是,它引发了以下例外:

异常抛出:'system.invalidcastException'in microsoft.visualbasic.dll 其他信息:从类型的" oracledate"转换为类型"日期"是无效的。

如果OracleDbType.Date无法转换为.NET Date类型,则该点是什么?如何将我的OracleDbType.Date取出我的功能,作为.NET Date(或日期?

好吧,所以这是最大的误解(我经常从ODP使用中看到(

Command.Parameters("outDate").Value

您只需检索CLR类型即可。实际上,您得到OracleDate-请参阅此

因此检索值的代码将为

dim dotNetVal as DateTime = Command.Parameters("outDate").Value.Value

并检查null

if Command.Parameters("outDate").Value.IsNull then

是的,这个演员 -

CDate(Command.Parameters("outDate").Value)

无效,因为您不能将OracleDate施加到DateTime

最新更新