varchar 值转换成数据类型 int 时失败的有关问题

varchar 值转换成数据类型 int 时失败的问题
private void button5_Click(object sender, EventArgs e)
        {

            if (comboBox2.Text == "")
            {
                MessageBox.Show("请输入查询条件", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //string sqlstr2 = "select nullahnum,goodsnum,goods,breed,broperson,brobran,spec,bronum,brotime,price,allprice,remark from tb_borrow where( goodsnum='" 

+ textBox8.Text + "' or goods='" + textBox8.Text + "')and brotime between'" + dateTimePicker2.Value.Date.ToShortDateString() + "' and '" + 

dateTimePicker3.Value.Date.ToShortDateString() + "' order by brotime";
                string sqlstr2 = "select ID,传感器编号,测点编号,监测值,监测日期 from 数据采集 where (  传感器编号='" + comboBox2.Text + "' or 测点编号='" + 

comboBox2.Text + "'or ID='" + comboBox2.Text + "')";
                DataSet ds3 = database.getSet(sqlstr2, "数据采集");
                if (ds3.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查询无结果", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    BinData();
                }

                else
                {
                    dataGridView1.DataSource = ds3.Tables[0];
                    this.dataGridView1.ReadOnly = false;
                    for (int i = 0; i <= 3; i++)
                    {
                        if (i == 0)
                        {
                            this.dataGridView1.Columns[i].ReadOnly = true;
                        }
                        else
                        {
                            this.dataGridView1.Columns[i].ReadOnly = false;
                        }
                    }
                }
            }
        }
以上代码是查询按钮的事件,点击后在下段代码出现“在将 varchar 值 'DB1-1' 转换成数据类型 int 时失败。”的错误
 public DataSet getSet(string str_sqlStr, string s_Tanble)
        {
            SqlConnection sqlcon = this.getCon();
            SqlDataAdapter sqlda = new SqlDataAdapter(str_sqlStr, sqlcon);
            DataSet ds = new DataSet();
            sqlda.Fill(ds, s_Tanble);    此行出现//在将 varchar 值 'DB1-1' 转换成数据类型 int 时失败。//
            return ds;
        }
------解决思路----------------------
DB1-1是where的参数还是select的结果。

我才是参数,你传DB1-1进去,但是要比较的column的类型去恩施int.
------解决思路----------------------
你的where里面,要比较 传感器编号 or 测点编号 or ID是不是等于comboBox2.Text。问题就在这里,这三个column里有一个是int类型的,而你的value是 DB1-1,它不是int。所以就转化不了了啊。
------解决思路----------------------
如果你额where添加里面的编号数据库表字段都是int类型
那么,你在界面采集用户输入的时候,用正则限制之内输入整数
或者
进行查询之前,先校验一下输入的值是否是Int型,如果不是给出相应的提示,待输入合法后再请求数据库
------解决思路----------------------
str_sqlStr  语句的问题。
------解决思路----------------------
引用:
str_sqlStr  语句的问题。

Fill 之前  在sql编译器中 执行str_sqlStr  看看能不能成功
------解决思路----------------------
varchar类型如果是 像 ‘123’这样的值可以转换,但是像你这样的值有字符的‘DB1-1’,是转换不了为int类型的
------解决思路----------------------
'DB1-1' 这种肯定转不了的!!
------解决思路----------------------
DB1-1这种字符串怎么可能转成int