莫名其妙的异常。

来源:百度知道 编辑:UC知道 时间:2024/06/19 07:34:03
string c = "";
if (this.CheckBox1.Checked)
{
c = "pID=" + this.tboxID.Text;
}
else
{
c = "pID like '%'";
}

if (this.CheckBox2.Checked)
{
c += " and pName like '%'"+ this.tboxname.Text+"'%'";
}

if (this.CheckBox3.Checked)
{
string sex = "";
if (this.rbtnman.Checked)
{
sex = "男";
}
else
{
sex = "女";
}
c += "and pSex=" + sex;
}

DataView dv = new DataView(doit.datasee());
dv.RowFilter = c;//异常点,异常信息如下。
//无法在 System.String 和 Syst

异常的问题不在于你的dv.RowFilter = c
这个赋值应该是没有问题的,关键在你的c本身。
应该是c += "and pSex=" + sex; 这一句出了错。
应该改成:
c += "and pSex='" + sex + "'";
字符串应该用引号包起来。

dv.RowFilter="string类型";

我上下看了5 6遍了,代码错误应该不在此,你带代码错误在看看,具体在哪一行可以看一下,然后找到那行,,

应该是 你要把 int类型想赋值给string类型的变量,转换不成功,所以报错,,就是类型间的错误你,你详细看看呢

上面我看不出来呀

dv.RowFilter跟的是string类型的,,。。。