private void RepeaterDataBind()
        {
            //DateTime bgTime=DateTime.Now;
            //DateTime edTime=DateTime.Now;
            string bgTime="";
            string enTime="";
            //if (txtBeginTime.Text.Trim() != "") {  bgTime= DateTime.Parse(txtBeginTime.Text.Trim());}
            //if (txtOverTime.Text.Trim() != "")  {  edTime = DateTime.Parse(txtOverTime.Text.Trim());}
            if (txtBeginTime.Text.Trim() != "") {  bgTime = txtBeginTime.Text.Trim().ToString;}
            if (txtOverTime.Text.Trim() != "")  {  edTime = txtOverTime.Text.Trim().ToString();}
            if (bgTime != null)
                {
                    if (!string.IsNullOrEmpty(strSQL))
                    {
                        strSQL = strSQL + " and ";
                    }
                    if (edTime != null)
                    {
                        strSQL = strSQL + " addtime between '" + bgTime + "' and '" + edTime + "'";
                    }
                    else
                    {
                        strSQL = strSQL + " addtime between '" + bgTime + "' and getdate() ";
                    }
                }
            }            rplist.DataSource = dal.GetModelList(PageSize, PageIndex, strSQL, ref recordCount, ref pageCount);
            rplist.DataBind();
            SetPagingState();
        }就保留了相关代码
前台是用的js控件 格式为:2009-12-03
这样查询查不出结果来啊?大家帮指点一下

解决方案 »

  1.   

    像这样的txtBeginTime.Text.Trim().ToString要转化为datetime格式的在查询
      

  2.   

    DateTime.Prase(txtBeginTime.Text.Trim().ToString);
      

  3.   

    现在是这样的
    private void RepeaterDataBind()
            {
                string strSQL = "";
                string keysStr = txtKeyWord.Text.Trim();
                string orderNum = txtOrderNum.Text.Trim();
                string userName = txtUserName.Text.Trim();
                string bgTime="";
                string edTime = "";
                if (txtBeginTime.Text.Trim() != "") {  bgTime=DateTime.Parse(txtBeginTime.Text.Trim()).ToString();}
                if (txtOverTime.Text.Trim() != "")  {  edTime =DateTime.Parse(txtOverTime.Text.Trim()).ToString();}            if (chkAll.Checked != true)
                {
                                    if (bgTime != "")
                    {
                        if (!string.IsNullOrEmpty(strSQL))
                        {
                            strSQL = strSQL + " and ";
                        }
                        if (edTime != "")
                        {
                            strSQL = strSQL + " addtime between '" + bgTime + "' and '" + edTime + "'";
                        }
                        else
                        {
                            strSQL = strSQL + " addtime between '" + bgTime + "' and getdate() ";
                        }
                    }
                }            rplist.DataSource = dal.GetModelList(PageSize, PageIndex, strSQL, ref recordCount, ref pageCount);
                rplist.DataBind();
                SetPagingState();
            }
      

  4.   

    根据组合条件把最后得到的sql语句放到查询分析器了看看 能不能查到
      

  5.   

    select * from User_BuyLesson where AddTime between '2008-2-1' and '2008-2-29'
    这样是没问题的
      

  6.   

    存储过程不会有问题。我好找到了点问题的所在。就是没有获取到的页面的值。我用的是js控件当点击 textbox后就会有值。我也特意点击了。是只读的。但是为什么后台就取不到了呢
      

  7.   

    多谢大家。一时糊涂 最小问题成了我最大天敌
    private void RepeaterDataBind()
            {
                string strSQL = "";
                string keysStr = txtKeyWord.Text.Trim();
                string orderNum = txtOrderNum.Text.Trim();
                string userName = txtUserName.Text.Trim();
                string bgTime=txtBeginTime.Text.Trim();
                string edTime = txtOverTime.Text.Trim();            if (chkAll.Checked != true)
                {
                    int userId = User_InfoManager.GetUserIdByName(userName);
                    if (!string.IsNullOrEmpty(keysStr))
                    {
                        if (userId != -1)
                        {
                            strSQL = strSQL + " (OrderNum like '%" + keysStr + "%' or Userid like'%" + userId + "%')";
                        }
                        else {
                            strSQL = strSQL + " (OrderNum like '%" + keysStr+"%')";
                        }
                    }                if (orderNum != "")
                    {
                        int _num = 0;
                        try { _num = int.Parse(orderNum); }
                        catch (Exception) { Response.Write("<script>alert('订单号输入有误');location.href='OrderByLesson.aspx';</script>"); ; }
                        if (!string.IsNullOrEmpty(strSQL))
                        {
                            strSQL = strSQL + " and ";
                        }
                        strSQL = strSQL + " OrderNum = " + _num + " ";
                    }
                    if (userName != "")
                    {
                        if (userId != -1)
                        {
                            if (!string.IsNullOrEmpty(strSQL))
                            {
                                strSQL = strSQL + " and ";
                            }
                            strSQL = strSQL + " UserId = '" + userId + "'";
                        }
                    }
                    if (bgTime != "")
                    {
                        if (!string.IsNullOrEmpty(strSQL))
                        {
                            strSQL = strSQL + " and ";
                        }
                        if (edTime != "")
                        {
                            strSQL = strSQL + " addtime between '" + DateTime.Parse(bgTime) + "' and '" + DateTime.Parse(edTime) + "'";
                        }
                        else
                        {
                            strSQL = strSQL + " addtime between '" + bgTime + "' and getdate() ";
                        }
                    }
                }            rplist.DataSource = dal.GetModelList(PageSize, PageIndex, strSQL, ref recordCount, ref pageCount);
                rplist.DataBind();
                SetPagingState();
            }
    结贴