我的变量是(日期和时间的组合)
我显示日期变量的控件是 this.datetxt.values
显示时间是 this.timetxt.text变量组合之后是这样的格式 变量1=2006-11-08  6:00 (日期和时间之间是有空格的!)
                         变量2=2006-11-08  17:00string sql = "select count(*) as 人数  from tab_Que_outin where 刷卡时间 between   变量1 and 变量2  and dept_id='0047'";希望有人指点

解决方案 »

  1.   


    string sql = "select count(*) as 人数  from tab_Que_outin where 刷卡时间 between "+ DateTime.Parse( 变量1 ) + "and" +DateTime.Parse( 变量2 ) +"and dept_id='0047'";
      

  2.   

    string sql = "select count(*) as 人数  from tab_Que_outin where 刷卡时间 between " + DateTime.Parse(this.DataTxt.Value ,this.AftOutsclstrtime.SelectedValue) + "and" + DateTime.Parse(this.DataTxt.Value,this.AftOutsclendtime.SelectedValue) + "and dept_id='0047'";楼上的你好!可是我这样写还是报错了!
      

  3.   

    变量1=this.DataTxt.value + this.AftOutsclstrtime.SelectedValue
    变量2=this.DataTxt.Value + this.AftOutsclendtime.SelectedValue
      

  4.   

    如果只是时间比较没必要格式化成你那样呀,而且如果是sql的话,要看你使用的具体的数据库是什么呢
      

  5.   

    string sql = String.Format("select count(*) as 人数 from tab_Que_outin where 刷卡时间 between '{0}' and '{1}' and dept_id='0047'",变量1,变量2);
      

  6.   

    也许是我的描述不够详细吧!
    我现在最想解决的是
    如何使变量变成这样!变量1=this.DataTxt.value + this.AftOutsclstrtime.SelectedValue
    (生成的日期是 2006-11-08 6:00)注意,我要的是日期和时间之间有空格
    变量2=this.DataTxt.Value + this.AftOutsclendtime.SelectedValue
    (生成的日期是 2006-11-08 12:00)