vb.net - 将 OracleDbType.Date 转换为 Date 无效
问题描述
我正在尝试从以下位置执行以下操作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
但是它会引发以下异常:
抛出异常:Microsoft.VisualBasic.dll 中的“System.InvalidCastException”附加信息:从“OracleDate”类型到“Date”类型的转换无效。
OracleDbType.Date
如果它不能转换为 .NETDate
类型有什么意义?我怎样才能把我的作为.NET (或日期?,我都试过了)OracleDbType.Date
从我的函数中传递出去?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
推荐阅读
- r - 将多个数据帧中的变量转换为R中的字符
- reactjs - 如何在 React 的嵌套上下文中更新状态
- python - 为什么我的协方差不能通过 scipy.optimize.curve_fit 计算?
- c# - 使用继承的 C# 问题 - 我的第一次
- python - 在 ubuntu 20.04LTS 上安装 pygame 的问题
- angular - Angular:通用表格组件,循环对象值
- python - 如何从另一个 python 脚本向 python 脚本发送多个“用户输入”?
- c# - 剃须刀类库中的通用控制器
- c# - 如何在 Visual Studio 中更改 C# 进度条样式
- ios - 在 segue 之后传递 Nil 值