strsqla = strsqla + "select cinvcode,cvencode from po_poview";
                if (txtvendor1.Text.Trim() != "")
                {
                    strsqla = strsqla + " where cvencode='" + txtvendor1.Text.Trim() + "'and cvencode <= '" + txtvendor2.Text.Trim() + "'";
                }
                if (txtinvcode1.Text.Trim() != "")
                {
                    strsqla = strsqla + "  and cinvcode='" + txtinvcode1.Text.Trim() + "' and cinvcode <='" + txtinvcode2.Text.Trim() + "'";
                }
                if (dtp1.Checked)
                {
                    strsqla = strsqla + " and dPODate >='" + dtp1.Value + "' and dPODate <='" + dtp2.Value + "'";
                }
                strsqla = strsqla + " group BY cinvcode,cvencode";

解决方案 »

  1.   

    " where cvencode='" + txtvendor1.Text.Trim() + "'and
    上面and前没有空格
      

  2.   

    拼接sql语句错误
    if (txtvendor1.Text.Trim() != "")
      {
      strsqla = strsqla + " where cvencode='" + txtvendor1.Text.Trim() + "'and cvencode <= '" + txtvendor2.Text.Trim() + "'";
      }如果这个条件不满足而满足下面的条件,那么你的sql语句中是不是就没有where关键字只有and了呢?报错的时候看看你拼接的完整的sql语句你就知道错在哪里了。
      

  3.   

    楼上正解,
    一般这样的问题,直接把拼好的SQL复制到查询分析器里运行就清楚了
      

  4.   

    如果你的操作是txtvendor1.Text.Trim() = ""是就必定会出现错误的,
    strsqla = strsqla + "select cinvcode,cvencode from po_poview";
      if (txtvendor1.Text.Trim() = "")
      {
      strsqla = strsqla + " where cvencode='" + txtvendor1.Text.Trim() + "'and cvencode <= '" + txtvendor2.Text.Trim() + "'";
      }
    //这里出现没有where而出现and的情况了!
      if (txtinvcode1.Text.Trim() != "")
      {
      strsqla = strsqla + " and cinvcode='" + txtinvcode1.Text.Trim() + "' and cinvcode <='" + txtinvcode2.Text.Trim() + "'";
      }
      if (dtp1.Checked)
      {
      strsqla = strsqla + " and dPODate >='" + dtp1.Value + "' and dPODate <='" + dtp2.Value + "'";
      }
      strsqla = strsqla + " group BY cinvcode,cvencode";