参考superdullwolf(超级大笨狼) 的 四级连动下拉列表 !
http://expert.csdn.net/Expert/topic/2523/2523437.xml?temp=.5512812

解决方案 »

  1.   

    在查询条件where 后使用比较年月日函数,如:year(时间字段) = selyear  //比较年
    year(时间字段) =selyear and month(时间字段) = selmonth   //比较年月 
    year(时间字段) =selyear and month(时间字段) = selmonth and day(时间字段)=selday  //比较年月日 
    或者
    datediff(day,时间字段,str(selyear)+'-'+str(selmonth)+'-'str(selday))) = 0 //比较两个日期相差0天,则为当天 ,使用连接字符串”-“ 合成一个时间
      

  2.   

    year(时间字段) = selyear  //比较年我曾试了行不通的。如year(时间字段)='2004'肯定要出错哈。
      

  3.   

    你可以用数据库直接操作
    year=select * from yourtable where 年字段=datediff(year,时间字段,"+DropDownList1.SelectItem.Text+")
    月:
    month=select * from yourtable where 月字段=datediff(year,时间字段,"+DropDownList2.SelectItem.Text+")
    日:
    day=select * from yourtable where 日字段=datediff(year,时间字段,"+DropDownList3.SelectItem.Text+")
      

  4.   

    不好意思。刚才给错了
    年查询:
    SQLstr="select * from medicine where datepart(yy,medicine_produce_date)='"+DropDownList1.SelectItem.Text +"'";
    月查询:
    SQLstr="select * from medicine where datepart(month,medicine_produce_date)='"+DropDownList2.SelectItem.Text+"'" ;
    日查询:
    SQLstr="select * from medicine where datepart(day,medicine_produce_date)='"+DropDownList3.SelectItem.Text+"'" ;
      

  5.   

    根据选择动态使用不同的sql语句,用程序控制
    选择年时,查询的范围为 dateField>= "2004.01.01" and dateField<= "2004.12.31"
    选择月时,查询的范围为 dateField>= "2004.04.01" and dateField<= "2004.04.31"
    选择日时,查询的范围为 dateField = "2004.04.14"
    (因为不知道你日期的存放格式,所给表达式不是真实sql语句)
      

  6.   

    什么数据库呀?
    Oracle中:
    select count(*),to_char(createtime,'yyyymm') from  table group by to_char(createtime,'yyyymm')
    SQL Server中可以用Date函数也可用convert,然后比较了
      

  7.   

    year(时间字段)=2004 //结果是int类型 ,可以在查询分析器中测试
      

  8.   

    select * from table where datediff(day,datetime,datetime);
    试试Datediff这个函数