0

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.

amarruffo
  • 418
  • 2
  • 5
  • 15
  • Can you post the code, including how you're creating the command and how you're setting the parameters? Normally you'd set an Oracle date from a System.Date value without regard to format. If you post the code I'm sure we can get this going for you. – Ed Gibbs Apr 16 '13 at 00:19

2 Answers2

1

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

Aidin
  • 2,134
  • 22
  • 26
0

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.