通过DataSet取到MS SQL里datatime类型的Date字段
如何与当前时间作比较?
System.DateTime current=DateTime.Now;
SqlDataAdapter date= new SqlDataAdapter("Select * from Shift_Cal where Day_Shift like 'A'",conn);
DataSet ds=new DataSet();
date.Fill(ds,"date");
System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
if (gettime > current) this.Label6.Text="Y";Build报错:System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
Cannot implicitly convert type 'object' to 'System.DateTime'
如何与当前时间作比较?
System.DateTime current=DateTime.Now;
SqlDataAdapter date= new SqlDataAdapter("Select * from Shift_Cal where Day_Shift like 'A'",conn);
DataSet ds=new DataSet();
date.Fill(ds,"date");
System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
if (gettime > current) this.Label6.Text="Y";Build报错:System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
Cannot implicitly convert type 'object' to 'System.DateTime'
解决方案 »
- 如何利用Jquery替换div里面的内容
- 【提问】一个关于集合重复与不重复的问题
- asp.net 在xxx.aspx.cs里建立数据库,怎么连接啊?~
- GridView实现删除数据的时候弹出对话框
- 判断用户是否登录,在每个页的page_load里都写吗
- 综合网站如何实现大量文章
- adapter.Update的问题???
- 类似于DataGrid+TreeView的样式,相当棘手,望高人给与指点.....
- 谁有好的dotnet的OA源代码的和我联系
- ================求:入门asp.net项目===============
- 关于Loadcontrol控件的问题,请大家指教
- 一个关闭的问题
SqlDataAdapter getshift=new SqlDataAdapter("Select * from Shift_Cal where Date > currenttime",conn);
DataSet ds=new DataSet();
getshift.Fill(ds,"shift");
string currentshift=ds.Tables["shift"].Rows[0]["Shift"].ToString();
this.Label6.Text=currentshift;
为什么报错啊?
多谢指导!
SqlDataAdapter date= new SqlDataAdapter("Select * from Shift_Cal where Day_Shift like 'A'",conn);
DataSet ds=new DataSet();
date.Fill(ds,"date");
string gettime=Convert.ToDateTime(ds.Tables["date"].Rows[0]["Date"]).ToString("yyyy-MM-dd hh:mm:ss");
if (Convert.ToDateTime(gettime) > Convert.ToDateTime(current)) this.Label6.Text="Y";
Build报错:System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
Cannot implicitly convert type 'object' to 'System.DateTime'//System.DateTime gettime=ds.Tables["date"].Rows[0]["Date"];
ds.Tables["date"].Rows[0]["Date"]它不能转换为时间类型,所以抱错