在对access数据库进行数据查询的时候要注意,where后面的条件要加单引号:

select * from 故障记录 where 故障现象代码='F001'


多条件查询实现的代码如下:

string sql = "select * from 故障记录 where";
 if(textBox_machine.Text!="")
 {
      sql += " 机器编号=" + "'" + textBox_machine.Text +"'"+ " and ";
 }
 if (textBox_false.Text != "")
  {
      sql += " 故障现象代码=" +"'"+ textBox_false.Text +"'"+ " and ";
  }
if (textBox_xian.Text != "")
  {
       sql += " 故障现象=" + "'" + textBox_xian.Text + "'" + " and ";
  }
if (textBox_cause.Text != "")
  {
       sql += " 故障原因代码=" + "'" + textBox_cause.Text + "'" + " and ";
  }
if (textBox_yuan.Text != "")
   {
        sql += " 故障原因=" + "'" + textBox_yuan.Text + "'" + " and ";
    }
if (textBox_time.Text != "")
    {
        sql += " 时间=" + "'" + textBox_time.Text + "'" + " and ";
    }
sql = sql.Substring(0, sql.Length - 5);