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";
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";
上面and前没有空格
if (txtvendor1.Text.Trim() != "")
{
strsqla = strsqla + " where cvencode='" + txtvendor1.Text.Trim() + "'and cvencode <= '" + txtvendor2.Text.Trim() + "'";
}如果这个条件不满足而满足下面的条件,那么你的sql语句中是不是就没有where关键字只有and了呢?报错的时候看看你拼接的完整的sql语句你就知道错在哪里了。
一般这样的问题,直接把拼好的SQL复制到查询分析器里运行就清楚了
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";