dt = sql.SelectSql("select * from einfo where SchID ='" + dt.Rows[0]["SchID"].ToString() + "'  order by class,srid");

解决方案 »

  1.   

    dt = sql.SelectSql("select * from einfo where SchID ='" + dt.Rows[0]["SchID"].ToString() + "'  and class=" + comboClass.SelectedValue.ToString() + " order by class,srid");
    是这句,不好意思.
      

  2.   

    dt.Rows[0]["SchID"].ToString() 改用变量
      

  3.   

    dt.Rows[0]["SchID"].ToString()从哪儿来的?代码贴全来看
      

  4.   

    class=" + comboClass.SelectedValue.ToString() + " order by class,srid" 少了单引号
    改成
    class='" + comboClass.SelectedValue.ToString() + "' order by class,srid"
      

  5.   

            private void button2_Click(object sender, EventArgs e)
            {
                dt = sqlc.SelectSql("select * from SchInfo where flag='1'");
                if (comboClass.SelectedValue.ToString() == "0")
                {
                    dt = sql.SelectSql("select * from einfo where SchID ='" + dt.Rows[0]["SchID"].ToString() + "'  order by class,srid");
                }
                else
                {
                    dt = sql.SelectSql("select * from einfo where SchID ='" + dt.Rows[0]["SchID"].ToString() + "'  and class=" + comboClass.SelectedValue.ToString() + " order by class,srid");
                }
                lblStatus.Text = "搜索到的记录数:" + dt.Rows.Count + " 条";            r.SetDataSource(dt);
                r.Refresh();
                ReportViewer.ReportSource = r;
            }
    刚开始到            if (comboClass.SelectedValue.ToString() == "0")这里的时候就不行了
    后来改成if (comboClass.SelectedValue!= null && comboClass.SelectedValue.ToString() == "0")
    然后到这里就停住了
      

  6.   

    应该是
    comboClass.SelectedValue.ToString()
    这个出问题了,因为你sql语句里也有这个建议你在if之前把comboClass.SelectedValue.ToString()打印出来看看到底是个什么值
      

  7.   

    改用comboClass.SelectedItem试一下
      

  8.   

    把sql语句打印出来,copy到查询分析器中运行,一眼看出错误
    dt = sql.SelectSql("select * from einfo where SchID ='" + dt.Rows[0]["SchID"].ToString() + "'  and class=" + comboClass.SelectedValue.ToString() + " order by class,srid"); 
      

  9.   

    确保那2个Tostring()得到正确的值.有可能你得到的object[]这样的值.用变量把.