在执行此语句
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
百思不得其解
还望哪位兄台能够指点迷津
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
百思不得其解
还望哪位兄台能够指点迷津
你可以在读取显示的时候yyyy-MM-dd了
日期类型.ToString("yyyy-MM-dd")
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
高人快快出现
改为 where UserName=\'"+yhm+"\'",sqlConnection1); 只要是SQL语句中出现的单引号。。
都改为\'就可以了。。
那样写没有错啊
而且有的地方用了String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)
那么写也没错啊
在C#中写就为 LastLoginTime=\'2005-10-10\' where ...