日期:2014-05-19  浏览次数:20490 次

时间格式问题,帮忙解决一下,谢谢
我在SQL数据库里定义了一个表,有这样的一个字段
create   table   aa(
updatetime   datetime   not   null
)
现在在.NET平台中通过按钮添加字段,
insert   语句如下:
string   time=System.DateTime.Now   .ToString   ();

    SqlCommand   cmd=new   SqlCommand   ( "insert   into   newsword   newsid,newstitle,newscontent,updatetime)   values( ' "+id+ " ', ' "+this.txtttile   .Text.Trim   ()   + " ', ' "+this.txtword   .Text   .Trim   ()+ " ', ' "+time+ " ' ",con);
可是运行的时候出错,说是时间格式错误呀,这一句该怎么写呢
先谢谢啦


------解决方案--------------------
sql语句少了个(括号
SqlCommand cmd=new SqlCommand ( "insert into newsword (newsid,newstitle,newscontent,updatetime) values( ' "+id+ " ', ' "+this.txtttile .Text.Trim () + " ', ' "+this.txtword .Text .Trim ()+ " ', ' "+ System.DateTime.Now.ToString()+ " ' ",con);