同一个表A,写了两个查询,一个是时间段查询。另外一个是名称模糊查询。 
时间段查询按钮= select * from A where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# "模糊查询按钮=select * from A where EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' "怎么可以把这两个按钮的查询变成一个按钮的某名称的某时间段查询???

解决方案 »

  1.   

    select * from A where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# and EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' "难道是这个???
      

  2.   

    select * from A where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# 
    and (EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%') "
      

  3.   

    or 的条件括起来就行了
    select * from A where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# "  and
            (EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' ")
      

  4.   

    试试这个:
    select * from A where (Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# ")  and  (EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' ") 
      

  5.   

    可以这样 select * from A where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# " and EnglishName like '%" + 
    textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' " 也可以这样:
    select * from (select * from A where EnglishName like '%" + textBoxSearchName.Text + "%' or ChineseName like '%"+ textBoxSearchName.Text+"%' ) B where Time1 between #" + dateTimePicker1.Text + "# and  #" + dateTimePicker2.Text + "# "