Reputation: 418
I'm trying to insert a date from .net to an Oracle 10g database. I'm sending the date on this format dd-MM-yyyy, but I get an error message which says "Invalid month", if I try to send the format dd-MMM-yyyy (I've tried this because when I do Ctype to OracleDate from a .NET date it shows me for example 01-JAN-2013), when I do this I get a message that says that oracle got text where it was expecting a number. I need some help, please.
Upvotes: 0
Views: 1780
Reputation: 2134
I assume you have a sql query with parameter like :dateToInsert in it.
In your .NET code, you need to pass the date as string to your parameters :
yourdate.ToString("MM-dd-yyyy"), OracleDbType.Varchar2
and the date portion of your sql query should be like this:
to_date(:dateToInsert, 'YYYY/MM/DD')
to_date is oracle's function to convert string to date format
Upvotes: 1
Reputation:
First of all,Date does not have any format...its the string which can be represented in the form of dd-MM-yyyy,this is string. Date will be taken as your current culture info,so e.g. If you pass 16-04-2013 then it will be implicitly converted as MM-dd-yyyy so it takes 16 as a month and you getting the error. You have to convert it to MM-dd-yyyy before passing,yourdate.ToString("MM-dd-yyyy")
,pass this wherever you want and you are done.
Upvotes: 0