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这种多个数据 该要如何实现呢
麻烦前辈们抽空解决!拜谢
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这种多个数据 该要如何实现呢
麻烦前辈们抽空解决!拜谢
解决方案 »
- 关于Button控件的事件与页面加载事件的关系
- javascript实现setInterval 输出自增数字?
- datatable里的数据不是从数据库里取的,但现在要把datatable里的数据插入到数据库原有的一张表里(此表已有数据)。
- WEB页面的目录树结构是怎么实现的 ?
- select 跟return
- --(在线等待)--为什么我的WEB应用程序发布时老是报不可恢复的生成错误!
- 放假没事写了个基类库...请高手指点...
- treeview控件的使用问题
- 如何把客户端的目录列表及文件显示在ListBox中或网页中
- 如何在全局象asp那样调用response对象?
- asp.net form表单 enctype ="multipart/form-data" 取值
- GridView的图片按钮切换
{
strSQL += " and GATEPASS_NO like '%"+s1+"%' ";
}
不行的 虽然拆分了查询条件 但是s1的内容等于是一个了 如果我要查询 a,b,c 你这样变成查abc了....
学习网络的,现在在实习让我改.net东西 我真的不会 如果你会 麻烦帮忙解决
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
如果把1,2,3换成txtGatePassNo.Text.Trim()该怎么写呢 求教
foreach(string s1 in str){
strSQL += " and GATEPASS_NO like '%"+s1+"%' ";
}
if (this.txtGatePassNo.Text.Trim() != "")
strSQL += " and '"+this.txtGatePassNo.Text.Trim()+"' LIKE '%'+GATEPASS_NO+',%'"
{
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;
}
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;
}
{
strSQL += " and GATEPASS_NO like '%"+s1+"%' ";
}
比如你输入a,b,c
and GATEPASS_NO like '%"+a+"%' and GATEPASS_NO like '%"+b+"%' and GATEPASS_NO like '%"+c+"%'";
然后用参数就行了
{
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;
}
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() + "%'";
}
}
{
strSQL += " or GATEPASS_NO like '%"+s1+"%' ";
}
如果txtGatePassNo输入1,2,3
就是查询的数据只要包涵1或者2或者3的都会查询出来,应该是OR 不是AND
如果是AND的话,查询出来的是既包含1同时包含2同时包含3的数据。
还是 (GATEPASS_NO LIKE '%a%' OR GATEPASS_NO LIKE '%b%' OR GATEPASS_NO LIKE '%c%')
foreach(string s1 in txtGatePassNo.Text.Trim().Split(','))
{
strSQL += " or GATEPASS_NO like '%"+s1+"%' ";
}
完成!