把一个日期值插入Sql Server 数据库时,这个日期值如何构造?在线求助 insert into test( id ,employdate ) values(1,"2002/03/09") 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 错了应该是单引号insert into test( id ,employdate ) values(1,'2002/03/09') insert into test(id ,employdate) values(1,'2002-03-09') 我 的 数据库 后台是sqlservere 是Pocket Pc上的,不知道也符合上面的规律吗 如我这样写,有错误: insert into test( id ,employdate )//其中employdate是datetime类型 values(1,"2002-03-09")请教高手帮忙更正一下,我上面也用的单引号,还是出错的'2002-09-09' string sql = "insert into test( id ,employdate ) values(@id,@employdate)";string conStr = 连接字符串SqlCommand command = new SqlCommand( sql,new SqlConnection( conStr ) );command.Parameters.Add( new SqlParameter("@id",SqlDbType.Integer);command.Parameters.Add( new SqlParameter("@employdate",SqlDbType.DateTime" );command.Parameters["@id"].Value = 1;command.Parameters["@employdate"].Value = DateTime.Parse("2002-03-09");command.Connection.Open();command.ExcuteNonQuery(); 你要string sdate="2002-09-09";sql="insert into test( id ,'"+sdate+"' )"; 试一下用dragontt(龙人)的方法。用单引号把日期括起来是没问题的,你的问题是否出在其他地方而跟这个日期无关呢?把错误提示粘出来看看。 xie xie da jia wo ma shang gei fen C# .net中关于文件输出流 StreamWriter 的一个简单问题 CheckBox的事件区别! C#windows 窗体combox 问一个很简单的问题关于winform刷新的。在线等,结贴。 c# 平台下有没有好的集群软件 在线求解:一道面试题目,正则表达式的 关于上传文件截取字符串问题 大家一起讨论下多线程 求大神:如何加快绘图速度? 如何不用using,引用包含文件的命名空间 关于读文件 DataView的Sort方法中排序字段的先后对排序结果有没有影响?
insert into test( id ,employdate ) values(1,'2002/03/09')
我这样写,有错误: insert into test( id ,employdate )//其中employdate是datetime类型 values(1,"2002-03-09")
请教高手帮忙更正一下,我上面也用的单引号,还是出错的'2002-09-09'
string conStr = 连接字符串
SqlCommand command = new SqlCommand( sql,new SqlConnection( conStr ) );
command.Parameters.Add( new SqlParameter("@id",SqlDbType.Integer);
command.Parameters.Add( new SqlParameter("@employdate",SqlDbType.DateTime" );
command.Parameters["@id"].Value = 1;
command.Parameters["@employdate"].Value = DateTime.Parse("2002-03-09");
command.Connection.Open();
command.ExcuteNonQuery();
string sdate="2002-09-09";sql="insert into test( id ,'"+sdate+"' )";
用单引号把日期括起来是没问题的,你的问题是否出在其他地方而跟这个日期无关呢?把错误提示粘出来看看。