初学,要做个作业,很急!
内容是:
对一个数据表表进行精确搜索。表如下:
表头:   A B C D E F G
         1 2 3 4 R 6 5
         9 4 5 T K E M
         8 5 L 4 7 0 2
搜索方式为:
每一条搜索用一个LABLE+一个TEXTBOX。LABLE提示用户输入关键词的类型,TEXTBOX为用户输入的关键词。
现在要进行组合搜索,定位出表中的一行。
七个LABLE
A
B
C
D
E
F
G
如用户想精确找到第三行:8 5 L 4 7 0 2
则需要在TEXTBOX1中输入8,第二个中输入5,第三个中输入L.....
输入七个条件后,搜索出结果。
语句怎么写,最好给段完整的代码。
别鄙视我哦,我初学的。

解决方案 »

  1.   

    select * from TableName where A='8' and  B='5' and  C='L'  D='4' and  E='7' and  F='0' and G='2'
      

  2.   

    表的列没有限制。
    如果有相同的列,比如说D列,第一行和第三行都有4,当在TEXTBOX4(D关键词输入的TEXTBOX)中输入4,那么就将第一行和第三行提取出来。但是如果再加一个条件,如在A中输入1,那么就可以定位到第一行了。
      

  3.   

    你是要做的自定义条件的查询 ,你可以判断TEXTBOX中是否有值 如果有值就把TEXTBOX里的值加到查询里
      

  4.   

    string where =""
    if (text1.text!="")
    {
      where="A="+text1.text;
    }
      

  5.   

    就是加个判断 如果8个都输入了.  执行 楼上的 否者 自己拼接一个查询将没有的参数 都用 like 操作  就行了
      

  6.   

    如果查询条件里没有值 就用like操作?
      

  7.   

    if(Label1.text!=null &&  Label2.text!=null && ...)
            {        }
            else
            {
            string s = "select * from TableName where" + "A like +"Label1.text+"%" + "and b like "+lable2.text+"%"...全部加上
             }这样写就OK了
      

  8.   

    to amandag(高歌) 
        昨天看你才2星啊.. 今天就变3了?....  太快了啊..
      

  9.   

    hm7921936() 提示有错误啊,lable处有错误啊,帮忙再看看咯
      

  10.   

    +"Label1.text+"%"这一段,说应输入;
      

  11.   

    而且,用户使用时是要在TEXTBOX中输入信息哦,TEXTBOX那块代码呢?
      

  12.   

    string s = "select * from TableName where " + Lable1.text +" like " + textbox1.text + "%" +
    " and " + Lable2.text +" like " + textbox2.text + "%"+" and " + Lable3.text +" like " + textbox3.text + "%"
    +" and " + Lable4.text +" like " + textbox4.text + "%" +....
      

  13.   

    string s = "select * from TableName where " + Label1.Text + " like " +"'"+ TextBox1.Text + "%'" +
            " and " + Label2.Text + " like " + "'" + TextBox2.Text + "%'" + " and " + Label3.Text + " like " + "'" + TextBox3.Text + "%'"
            + " and " + Label4.Text + " like " + "'" + TextBox4.Text + "%'" + " and " + Label5.Text + " like " + "'" + TextBox5.Text + "%'"
            + " and " + Label6.Text + " like " + "'" + TextBox6.Text + "%'" + " and " + Label7.Text + " like " + "'" + TextBox7.Text + "%'"
            + " and " + Label8.Text + " like " + "'" + TextBox8.Text + "%'";
      

  14.   

    多条件可以参考以下string where =""
    if (text1.text!="")
    {
      where=" and A="+text1.text;
    }