谁能帮我改改
public DataTable ShowFindscout(string name,string verid){
string strline=name;
string [] aryline=null;
string ss="";
aryline = strline.Split(new char[] { ',' });
if(aryline.Length>=2)
{
for (int j = 0; j< aryline.Length; j++)
{
if (j==(aryline.Length-1))
{
ss=ss+"Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '% or "+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%'";
}
else
{
ss=ss+"Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '% or "+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%' or ";
}
}
}
else
{
for (int j = 0; j< aryline.Length; j++)
{
ss="Coupon LIKE '%" +aryline[j]+"%' or "+"Chrcontent LIKE '%"+aryline[j]+"%' or "+"Keyword LIKE '%"+aryline[j]+"%'";
}
}
myConn.dbQuery("select Nid,Chrtitle,Chrcontent,Dtappenddate from Life_find where Isopen=1 and verid="+verid+" and ("+ss+") ");
return myConn.FileValue;
}
上面是我写的代码 传值例如:a,b,c
得到 SQL入下
select * from where verid=2 and (Coupon LIKE '%a' or Chrcontent LIKE '%a' Keyword LIKE '%a' or Coupon LIKE '%b' or Chrcontent LIKE '%b' Keyword LIKE '%b' or Coupon LIKE '%c' or Chrcontent LIKE '%c' Keyword LIKE '%c')
现在想把上面的方法改下 传值成 a,b,c|A,B,C
得到SQL如下:请帮我改下
select * from where verid=2 and (Coupon LIKE '%a' or Chrcontent LIKE '%a' Keyword LIKE '%a' or Coupon LIKE '%b' or Chrcontent LIKE '%b' Keyword LIKE '%b' or Coupon LIKE '%c' or Chrcontent LIKE '%c' Keyword LIKE '%c') and (Coupon LIKE '%A' or Chrcontent LIKE '%A' Keyword LIKE '%A' OR Coupon LIKE '%B' or Chrcontent LIKE '%B' Keyword LIKE '%B')
--------------------编程问答-------------------- 数据库里的内容好像不区分大小写???? --------------------编程问答-------------------- 最好写成存储过程
注入危险 --------------------编程问答-------------------- 1、数据库不区分a,A
2、用and连接a,A不合适吧 --------------------编程问答-------------------- a,b,c|A,B,C
不是大小写 是 值都代表一个值
--------------------编程问答-------------------- 代码倒是该改一下
public DataTable ShowFindscout(string name,string verid)
{
string strline=name;
string [] aryline=null;
string ss="";
aryline = strline.Split(new char[] { ',' });
for (int j = 0; j< aryline.Length; j++)
{
ss += "(Coupon LIKE '%" +aryline[j]+"' or Chrcontent LIKE '%"+aryline[j]+"' or Keyword LIKE '%"+aryline[j]+"%') or ";
}
myConn.dbQuery("select Nid,Chrtitle,Chrcontent,Dtappenddate from Life_find where Isopen=1 and verid="+verid+" and ("+ss.Trim(" or ")+") ");
return myConn.FileValue;
}
补充:.NET技术 , ASP.NET