在执行此语句     
SqlCommand sqlCommand2=new SqlCommand("update UserInfo set UserTime=UserTime+1,LastLoginTime="+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+" where UserName='"+yhm+"'",sqlConnection1); 
数据库里LastLoginTime显示的时间是1905-6-7 
百思不得其解 
还望哪位兄台能够指点迷津 

解决方案 »

  1.   

    数据库里存的只是datetime型的,不管MM还是M格式的,
    你可以在读取显示的时候yyyy-MM-dd了
      

  2.   

    同意yezie(椰子.Net) 说的~
      

  3.   

    除非你把数据库的那个字段类型改成char相关的类型。或者在显示的时候把那个日期字段格式化成yyyy-MM-dd:例如
    日期类型.ToString("yyyy-MM-dd")
      

  4.   

    上面说的不清楚,具体的是这样的,希望能再次得到指点错的地方是这样的: 
       SqlCommand sqlCommand2=new SqlCommand("update UserInfo set UserTime=UserTime+1,LastLoginTime="+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+" where UserName='"+yhm+"'",sqlConnection1); 
    对的地方是: 
    SqlCommand sqlCommand2=new SqlCommand("insert into UserInfo (UserName,Password,Email,UserDJ,UserTime,LoginTime) values('"+TextBoxyhm.Text+"','"+TextBoxmm.Text+"','"+TextBoxdzxx.Text+"',0,1,'"+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+"')",sqlConnection1); 昨天错的显示时间是    1905-6-3  
    今天再用显示的时间是   1905-6-4 
      

  5.   

    郁闷ing......................
    高人快快出现
      

  6.   

    where UserName='"+yhm+"'",sqlConnection1); 
    改为 where UserName=\'"+yhm+"\'",sqlConnection1); 只要是SQL语句中出现的单引号。。
    都改为\'就可以了。。
      

  7.   

    可是不用String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)时
    那样写没有错啊
    而且有的地方用了String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)
    那么写也没错啊
      

  8.   

    LastLoginTime="+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+" where UserName='"+yhm+"'",sqlConnection1); 那你得出的字符串为:LastLoginTime=2005-10-10 where ...这样的格式正确的SQL语句应为   LastLoginTime='2005-10-10' where ...
    在C#中写就为        LastLoginTime=\'2005-10-10\' where ...