日期:2014-05-18  浏览次数:20855 次

老提示关键字‘and’附近语法错误 高手帮我分析下
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";



------解决方案--------------------
拼接sql语句错误
if (txtvendor1.Text.Trim() != "")
{
strsqla = strsqla + " where cvencode='" + txtvendor1.Text.Trim() + "'and cvencode <= '" + txtvendor2.Text.Trim() + "'";
}

如果这个条件不满足而满足下面的条件,那么你的sql语句中是不是就没有where关键字只有and了呢?

报错的时候看看你拼接的完整的sql语句你就知道错在哪里了。