我使用C#语言,往Oracle数据库中插入信息,以下面的一条语句来形成插入语句。
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+Info.time+"','"+Info.createBy+"')";
其中Info.ID,Info.time,Info.createBy都是string。
Info.time=GetCurrentTimeStr();
public static string GetCurrentTimeStr()
{
string str1=DateTime.Now.Month.Tostring();
string str2=DateTime.Now.Day.Tostring();
string str3=DateTime.Now.Year.Tostring();
string str4=DateTime.Now.Hour.Tostring();
string str5=DateTime.Now.Minute.Tostring();
string str6=DateTime.Now.Second.Tostring();
return(str1+"/"+str2+"/"+str3+"/"+" "+str4+":"+str5+":"+str6);
}结果老是说无效的月份。
后来我把
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+Info.time+"','"+Info.createBy+"')";
改成
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+DateTime.Now+"','"+Info.createBy+"')";
却说”文字与格式字符串不匹配“我实在不知道这个Oracle的插入语句该怎么写了,好像关键问题是出在哪个时间的插入上,信息表中创建时间为DATE型数据,求各位高手指点~
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+Info.time+"','"+Info.createBy+"')";
其中Info.ID,Info.time,Info.createBy都是string。
Info.time=GetCurrentTimeStr();
public static string GetCurrentTimeStr()
{
string str1=DateTime.Now.Month.Tostring();
string str2=DateTime.Now.Day.Tostring();
string str3=DateTime.Now.Year.Tostring();
string str4=DateTime.Now.Hour.Tostring();
string str5=DateTime.Now.Minute.Tostring();
string str6=DateTime.Now.Second.Tostring();
return(str1+"/"+str2+"/"+str3+"/"+" "+str4+":"+str5+":"+str6);
}结果老是说无效的月份。
后来我把
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+Info.time+"','"+Info.createBy+"')";
改成
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"','"+DateTime.Now+"','"+Info.createBy+"')";
却说”文字与格式字符串不匹配“我实在不知道这个Oracle的插入语句该怎么写了,好像关键问题是出在哪个时间的插入上,信息表中创建时间为DATE型数据,求各位高手指点~
解决方案 »
- 如何快速提高写sql的能力?
- 用sql能不能查出机构的下两级机构
- 求教,展示下及科目方式
- 求助:Orcale表设置两个clob,两个clob字段的内容颠倒了!!!!!
- 求教一个存储过程(动态游标)
- 大家谈谈索引在进行select,update,delete,insert操作时对数据库性能的影响
- 回滚段文件丢失,重建失败,该如何?
- 怎么找到隐式cursor最后一条记录
- 请问 "ORA-01536:space quota exceeded for tablespace 'POST_INDX'"是表示什么,如何解决问题?急!
- Oracle9中PL SQL存储过程写文件的字符集问题,急求答案,解决后分数任意!
- ORA--2108: Message -2108 not found; product=RDBMS; facility=ORA
- oracle存储过程问题
public static string GetCurrentTimeStr()
{
return "to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+ "','yyyy-mm-dd hh24:mi:ss')";
}
//Info.time两边的'不要用了
string sqlString="Insert into 信息表(节点ID,创建时间,创建人)Values('"+Info.ID+"',"+Info.time+",'"+Info.createBy+"')";