Link to home
Start Free TrialLog in
Avatar of Dinesh Kumar
Dinesh KumarFlag for India

asked on

Passing date from c# to Oracle

Hi,

I have tried many ways to insert a date into oracle database from a query being run from c# .

but not able to.

please help.

A screen shot is also attached.
code.png
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Expecting Oracle to implicitly convert a string into a date is not always safe.  Having Oracle explicitly convert a string into a data is the way to go.  Try:
...DATE_OF_TI_REMARKS=to_date('" + Date + "','DDMMMYYYY HH24:MI:SS') where ...
SOLUTION
Avatar of OP_Zaharin
OP_Zaharin
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dinesh Kumar

ASKER

don't you think that  I should know the server date time format for oracle insert first?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oracle actually stores dates internally as a decimal number where the integer portion is the number of days since the epoch (1/1/1970) and the fractional portion is the fraction of a day.  You cannot specify dates to Oracle in that format.  The TO_DATE() function supports a wide variety of formats that can be converted into an internal date value.  Have a look at the links I provided ... they detail the actual format options.
The TO_DATE() function is the Oracle method to 'cast' strings into datetime datatypes.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

The best way is to use bind variables to help protect against SQL injection and help SQL parsing.

Delcare a native date variable:
http://www.oracle.com/technetwork/issue-archive/2005/05-sep/o55odpnet-101704.html

Then you might not have to worry about to_char conversions.

>>don't you think that  I should know the server date time format for oracle insert first?

Mentioned above, Oracle uses sysdate.  Not sure what you are using it for based on the code you posted.
@lwadwell

That is not how dates are internally stored.  They are stored in a 7 byte notation.  The best explanation of how they are internally stored (that I have found) is here:

http://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_04dat.htm#sthref442

They are not stored as a number of days since the epoch.  You cannot get the significant date range the Oracle supports using that.
thanks @johnstone ... I will strive to remember that in future.  I am struggling to remember where I picked my idea from - perhaps I have it confused with something else I have worked with in my past ... it has me thinking now.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry OP_Zaharin's first comment was also part of the solution.
- you can ask for assistance on the from the site moderator by clicking the "Request Attention icon" to change the accepted answer.
I've requested that this question be closed as follows:

Accepted answer: 450 points for angelIII's comment #a38344921
Assisted answer: 0 points for meetDinesh's comment #a38375488

for the following reason:

Thanks
meetDinesh,

I unaccepted this because in http:#a38382610 you stated that OP_Zaharin should get some of the points.

You have again failed to give him any.  Therefore I'll object to this closing and hopefully you can close this properly.