我使用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型数据,求各位高手指点~
解决方案 »
- Oracle有没有这样一个函数
- SQL:在循环中,抽出的数据以6万件为单位,出力文件title的功能怎样实现
- 这句在Oracle中怎么写
- JAVA读取文本文件,然后执行该SQL语句,出现java.sql.SQLException: ORA-00911: invalid character报错
- 求一简单树形结构的运算结果,请熟悉的朋友指点一下
- 关于字符串的查询!
- sql
- 2 我的oracle是不是没有安装完全?请教大家了!谢谢!
- 改变字符集
- oracle 中select语句返回记录数
- 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+"')";