例如:
创建三个combox
第一个combox1的值为:未选择,男,女
第二个combox2的值为:未选择,计算机科学系,金融系
第三个combox3的值为:未选择,专科,本科现在的问题是如何判断哪个combox有选,哪个没选.如果这样先写一条 select * from student where sex=combox1.text and cs=combox2 and xl=combox3三个都是初始"未选择"
在选择"男"和"专科"时,DataGridView显示查找出"男"和"专科"的行,可是系别那里就不能有"and cs=combox2 "如何根据combox选取的值来写where语句

解决方案 »

  1.   

    and cs=combox2改and (cs=combox2 or combox2.text='未选择')
      

  2.   

    string sql=" select * from student where 1=1"
    if(combox1.text!="")
    {
        sql=sql+" and sex=combox1.text";
    }
    if(combox2.text!="")
    {
        sql=sql+" and cs=combox1.text";
    }if(combox3.text!="")
    {
        sql=sql+" and xl=combox1.text";
    }
      

  3.   

    可以用index属性吧,没有选择的时候index == -1;
      

  4.   

    可能理解有点误差,你的“未选择”是作为comboBox的第一个内容了?如果这样你可以直接判断文本是否是“未选择”或者可以判断index ==0;
    如果你所谓的“未选择”是comboBox的空白内容,那么判断index == -1;就好了