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;
}