我想进行查询,根据输入的设备编号,找出表中的数据,并且当没有查询到的时候,显示:设备未借出。
我的问题是:
if (ds.Tables[0] == null)// 如果没有查询到,显示设备没有借出
是不是不能这样判断?应该怎么判断呢?
原代码如下:
string tempValue = comboBox1.Items[comboBox1.SelectedIndex].ToString();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DeviceMng;Integrated Security=True"); if (tempValue == "设备编号")
{
string co = "select * from t_Lend where 设备编号='" + this.textBox1.Text + "'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(co, con);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
if (ds.Tables[0] == null)// 如果没有查询到,显示设备没有借出
{
MessageBox.Show("设备未借出");
}
}感谢各位大侠了
我的问题是:
if (ds.Tables[0] == null)// 如果没有查询到,显示设备没有借出
是不是不能这样判断?应该怎么判断呢?
原代码如下:
string tempValue = comboBox1.Items[comboBox1.SelectedIndex].ToString();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DeviceMng;Integrated Security=True"); if (tempValue == "设备编号")
{
string co = "select * from t_Lend where 设备编号='" + this.textBox1.Text + "'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(co, con);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
if (ds.Tables[0] == null)// 如果没有查询到,显示设备没有借出
{
MessageBox.Show("设备未借出");
}
}感谢各位大侠了
{
MessageBox.Show("设备未借出");
}
dataGridView1.DataSource = ds.Tables[0];