如何将DateTime C#语言保存到oracle10g数据库 [英] how can save DateTime c# language to oracle10g database

查看:198
本文介绍了如何将DateTime C#语言保存到oracle10g数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个表==创建表newstudent(注册int,名称varchar2(20),DoJoin日期); 在C#中,当我键入

there is a table== create table newstudent(enroll int, name varchar2(20), DoJoin date); in c# when i type

oraclecommand(1,'amit purohit', DateTime.Now());
//Error found 'nvalid month'
oraclecommand(1,'amit purohit', String.Format("{0:dd-MMM-yyyy}"));
//problme that save only date into database but i need time also. like '11-AUG-2009 11:22:32.0'
oraclecommand(1,'amit purohit', String.Format("{0:dd-MMM-yyyy hh:mm:ss}")
//also error get like string picture format in date time values

推荐答案

您的问题之一可能是您的日期格式与Oracle错误.

One of your problems may be the fact that your date is in the wrong format for Oracle.

Oracle接受 yyyy/mm/dd 日期格式,我看到您没有使用它.

Oracle accepts the yyyy/mm/dd date format which I can see you're not using.

我与Jon Skeet一起使用oracle命令,但您可能想尝试在字符串中创建普通的SQL查询,然后运行查询.

I'm with Jon Skeet on this one for the oraclecommand but you maybe want to try creating a normal SQL Query inside a string and then running the query.

您可以使用to_date函数将日期转换为正确的格式.

You can use the to_date function to convert your date into the correct format.

insert into table_name
(date_field)
values
(to_date('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));

(通过标准日期和时间格式字符串)

或者,另一方面,您可以尝试使用某些C#函数将日期转换为Oracle可接受的正确格式: Oracle/PLSQL:将日期/时间值插入Oracle表

Or on the other hand you may try converting the date to a proper Oracle accepted format using some C# functions: Oracle/PLSQL: Insert a date/time value into an Oracle table

这篇关于如何将DateTime C#语言保存到oracle10g数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆