把一个日期值插入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#中serialport控件的pinchanged使用 VS操作问题 求所有N*N的矩阵 UdpClient 实例化时无参数和用端口参数:2112 ,它们之间有什么区别啊? .net页面中包含js文件的问题!!!!!!! datatable合并行 高分求C#云台控制源码 VS 2008 自带的安装程序 如何制作出兼容NET4,NET4.5的程序啊 求一小段delphi代码转C# 关于页面传值出现的奇怪问题,急等解决!!!!!!!!!!! 关于读文件 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+"' )";
用单引号把日期括起来是没问题的,你的问题是否出在其他地方而跟这个日期无关呢?把错误提示粘出来看看。