首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

拼凑字符串sql语句查询

2012-08-03 
拼接字符串sql语句查询string sql “”;if(abc!){sql“and dfg(字段名)abc”;sql+select .... ...}请教

拼接字符串sql语句查询
string sql =“”;
if(abc!="")
{
  sql=“and dfg(字段名)=abc”;
  sql+=select .... ...
}
请教各位高手怎样拼接字符串进行查询,并让的where语句任意加上并执行下去...,具体语法怎么写啊?高手,请教了(asp.net)

[解决办法]
例子

C# code
String strSql=String.Format("SELECT * FROM yourTable WHERE 1=1 ")if(abc!=""){  strSql+=" and 字段名="+abc;或者strSql+=" and 字段名 LIKE '%"+abc+"%'";}
[解决办法]
看这样:
C# code
string sql = "SELECT 字段 FROM 表";if(abc != ""){  sql += " and 条件=" + abc;}//……执行
[解决办法]
失误,纯粹失误:
看这样:
C# code
string sql = "SELECT 字段 FROM 表";if(abc != ""){  sql += " WHERE 字段=" + abc;}//……执行
[解决办法]
探讨
例子
C# code
String strSql=String.Format("SELECT * FROM yourTable WHERE 1=1")if(abc!="")
{
strSql+=" and 字段名="+abc;或者strSql+=" and 字段名 LIKE '%"+abc+"%'";
}

热点排行