string strSQL = @"select *  from 表1  where 1=1";
        if (this.txtGatePassNo.Text.Trim() != "")
            strSQL += " and GATEPASS_NO this.txtGatePassNo.Text.Trim()是要输入的查询条件 ,格式是 a,b,c这种以逗号隔开的字符串   ,GATEPASS_NO是查询条件要匹配的字段
   该如何实现呢? 如果是单个查询a   很好写啊  GATEPASS_NO like  '%" + this.txtCAR_NO.Text.Trim() + "%'";
  关键是现在this.txtGatePassNo.Text.Trim()输入的值可以是  a,b,c,d这种多个数据  该要如何实现呢 
         麻烦前辈们抽空解决!拜谢

解决方案 »

  1.   

    你循环一下 txtGatePassNo 然后拼一个 sql语句出来 不行吗
      

  2.   

    foreach(string s1 in txtGatePassNo.Text.Trim().Split(','))
    {
     strSQL += " and GATEPASS_NO  like '%"+s1+"%' ";
    }
      

  3.   


    不行的 虽然拆分了查询条件 但是s1的内容等于是一个了  如果我要查询 a,b,c  你这样变成查abc了....
      

  4.   


    学习网络的,现在在实习让我改.net东西 我真的不会  如果你会 麻烦帮忙解决
      

  5.   

    输入的查询内容,比如  xiao,da,san 这些   也就是说查询出的内容是包含 xiao    da  san这些字段的内容
      

  6.   

    DECLARE @idlist varchar(100)
    SET @idlist='1,2,3'--查询
    SELECT * FROM tbname WHERE CHARINDEX(','+RTRIM(fdname)+',',','+@idlist+',')>0
    SELECT * FROM tbname WHERE PATINDEX('%,'+RTRIM(fdname)+',%',','+@idlist+',')>0
    SELECT * FROM tbname WHERE ','+@idlist+',' LIKE '%,'+RTRIM(fdname)+',%'
    GO
      

  7.   

    select * from table where charindex(','+@fname+',',','+Expand+',')>0
      

  8.   


    如果把1,2,3换成txtGatePassNo.Text.Trim()该怎么写呢 求教
      

  9.   

    string[] str = txtGatePassNo.Text.Trim().Split(',');
    foreach(string s1 in str){
    strSQL += " and GATEPASS_NO like '%"+s1+"%' ";
    }
      

  10.   

    string strSQL = @"select * from 表1 where 1=1";
      if (this.txtGatePassNo.Text.Trim() != "")
      strSQL += " and '"+this.txtGatePassNo.Text.Trim()+"' LIKE '%'+GATEPASS_NO+',%'"  
      

  11.   

     for (int i = 0; i < arrGatePassNo.Length; i++)
            {
                if (i == 0)
                {
                    strCon = " and (GatePass_No like '%" + arrGatePassNo[i] + "%' ";
                    if (i + 1 == arrGatePassNo.Length)
                    {
                        strCon += ")";
                    }
                }
                else if (i < arrGatePassNo.Length - 1)
                    strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%' ";
                else
                    strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%')";        }
            if (GatePassNo != "")
            {
                strSQL += strCon;
            }
      

  12.   

    没人说对的  我贴个正确的吧  是公司项目经理帮我弄的
     for (int i = 0; i < arrGatePassNo.Length; i++)
            {
                if (i == 0)
                {
                    strCon = " and (GatePass_No like '%" + arrGatePassNo[i] + "%' ";
                    if (i + 1 == arrGatePassNo.Length)
                    {
                        strCon += ")";
                    }
                }
                else if (i < arrGatePassNo.Length - 1)
                    strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%' ";
                else
                    strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%')";        }
            if (GatePassNo != "")
            {
                strSQL += strCon;
            }
      

  13.   

    foreach(string s1 in txtGatePassNo.Text.Trim().Split(','))
    {
    strSQL += " and GATEPASS_NO like '%"+s1+"%' ";
    }
    比如你输入a,b,c 
     and GATEPASS_NO like '%"+a+"%' and GATEPASS_NO like '%"+b+"%' and GATEPASS_NO like '%"+c+"%'";
      

  14.   

    也可以定义一个参数来些会简单点。string paramCode=this.txtGatePassNo.Text.Trim();
    然后用参数就行了
      

  15.   

    for (int i = 0; i < arrGatePassNo.Length; i++)
      {
      if (i == 0)
      {
      strCon = " and (GatePass_No like '%" + arrGatePassNo[i] + "%' ";
      if (i + 1 == arrGatePassNo.Length)
      {
      strCon += ")";
      }
      }
      else if (i < arrGatePassNo.Length - 1)
      strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%' ";
      else
      strCon += " or GatePass_No like '%" + arrGatePassNo[i] + "%')";  }
      if (GatePassNo != "")
      {
      strSQL += strCon;
      }
      

  16.   

    哎,我凑,前段时间客户也要求做类似这样的查询,想来想去,除了盘古分词,就是这种最原始的了:多个条件组合,输入查询条件以逗号隔开,可快速定位信息:                string str_Where ="";
                    string strWhe = 文本框的值;
                    string[] aaa = strWhe.Split(',');//以逗号拆分
                    if (aaa.Length > 0)
                    {
                        for (int i = 0; i < aaa.Length; i++)
                        {
           
                             //拼接
                            if (str_Where == "")
                                str_Where = " _Name like '%" + aaa[i].ToString() + "%'";
                            else
                                str_Where += " and _Name like '%" + aaa[i].ToString() + "%'";
                        }
                    }
      

  17.   

    foreach(string s1 in txtGatePassNo.Text.Trim().Split(','))
    {
    strSQL += " or GATEPASS_NO like '%"+s1+"%' ";
    }
    如果txtGatePassNo输入1,2,3
    就是查询的数据只要包涵1或者2或者3的都会查询出来,应该是OR 不是AND
    如果是AND的话,查询出来的是既包含1同时包含2同时包含3的数据。
      

  18.   

    不知楼主想要的是GATEPASS_NO LIKE '%a%b%c%'
    还是 (GATEPASS_NO LIKE '%a%' OR GATEPASS_NO LIKE '%b%' OR GATEPASS_NO LIKE '%c%')
      

  19.   

    拆分,拼串
    foreach(string s1 in txtGatePassNo.Text.Trim().Split(','))
        {
         strSQL += " or GATEPASS_NO  like '%"+s1+"%' ";
        }
    完成!