Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Casting from OracleDate to VB.NET date

205783Apr 4 2006 — edited Jun 25 2010
OK, I have a proc something like this:

procedure GetADate(my_id in number,
d_due_date out date) is
begin
select mydate as Due_Date
into d_due_date
from ...
where id = my_id;
...

I call this via VB.NET similar to the following:

Dim cmd As New OracleCommand("mypackage.GetADate", cn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("MyID", OracleDbType.Double, CInt(id.Text), ParameterDirection.Input)
.Parameters.Add("DueDate", OracleDbType.Date, ParameterDirection.Output)
.ExecuteNonQuery()
End With

Now, all I want to do is to get the date from the DueDate parameter and stick it into a VB.NET Date variable. I have searched this forum and have tried just about everything suggested, but each time it always comes back and tells me that it cannot cast from an OracleDate to a Date field. I.E. I can't do the following:

Dim MyDate as Date = .Parameters("DueDate").Value

I even tried Ctype(.Parameters("DueDate").Value, Date) and that still gives the same error. The ONLY way I have been able to do this is to convert the parameter output variable to a string and then back to a VB.NET date, as such:

Dim MyDate as Date = CType(.Paramters("DueDate").Value.ToString, Date)

But this seems dumb. Why go thru two different casts (Oracle Date to String to .NET Date)? What is the best way to get an Oracle stored procedure output date into a .NET date field? This is perplexing me greatly. Thanks in advance.

Tom
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2010
Added on Apr 4 2006
5 comments
10,311 views