求SQL模糊查找语句与C#代码 本帖最后由 viphk 于 2010-10-15 12:55:17 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from 表 where 关键字 like '%15%' 查找关键字含有带有15的所有结果集 select * from merchandise where title like '%15日%' and (content like '%北京市%' or content like '%化妆品%' or content like '%香水%') select * from 表 where 日期 like '%15%' and 关键字 like '%+"包含的关键字"+%' 拼sql: string[] gj = TextBox1.Text.Split(','); string whe = " where ("; for (int i = 0; i < gj.Length; i++) { whe += "( 内容字段 like '%" + gj[i] + "%') or "; } whe = whe.Substring(0, whe.Length - 3)+") "; string sql = "select * from 表 " + whe+ " and (日期字段 between ... and ... )"; LZ看到这个还没有思路么、把输入的关键字挨个读取出来;若是不知道关键字的个数可将关键字放到数组中、然后根据关键字的个数控制content like '%关键字%'的数量 接9楼:TextBox1.Text="北京市,香水,化妆品"; 我的那个不行吗????????页面代码:string sql="select * from biaoming where 1=1 and ";if(txtDateTime.text.trim().leng>0){ sql+="'%"+this.txtDataTime.text+"%'";}if(this.txtContent.text.trim().leng>0){ int index=this.txtContent.text.indexof(','); string[] strContent=null; if(index>0) { strContent=this.txtContent.text.split(new char[]{','},StringSplitOptions.None); for(int i=0;i<strContent.length;i++) { sql+=" '%"+strContent[i]+"%' "; } }else { sql+=" '%"+this.txtContent.text+"%' "; }} c#异或的加密解密,本人计算机二级还没考的水平 dataGridView 怎么获取文件夹里选择的文件 Windows服务程序调用axWebBrowser控件出错: c# Socket中tcpListenr.stop 和直接结束监听进程有区别 namespace CGUDF.GIS.ProGIS 这是什么命名空间啊 Visual Studio 2008 在新建c++项目时提示库没有注册 特急怎么确定ASP.NET应用程序中TextBox控件内光标的位置。 求 Adobe Acrobat 文件转换的 cmd命令行 如何通过行政区域编码查询邮政编码 关于二进制文件续写问题 .net连接mysql
string[] gj = TextBox1.Text.Split(',');
string whe = " where (";
for (int i = 0; i < gj.Length; i++)
{
whe += "( 内容字段 like '%" + gj[i] + "%') or ";
}
whe = whe.Substring(0, whe.Length - 3)+") ";
string sql = "select * from 表 " + whe+ " and (日期字段 between ... and ... )";
LZ看到这个还没有思路么、把输入的关键字挨个读取出来;
若是不知道关键字的个数可将关键字放到数组中、然后根据关键字的个数控制content like '%关键字%'的数量
TextBox1.Text="北京市,香水,化妆品";
页面代码:
string sql="select * from biaoming where 1=1 and ";
if(txtDateTime.text.trim().leng>0)
{
sql+="'%"+this.txtDataTime.text+"%'";
}
if(this.txtContent.text.trim().leng>0)
{
int index=this.txtContent.text.indexof(',');
string[] strContent=null;
if(index>0)
{
strContent=this.txtContent.text.split(new char[]{','},StringSplitOptions.None);
for(int i=0;i<strContent.length;i++)
{
sql+=" '%"+strContent[i]+"%' ";
}
}else
{
sql+=" '%"+this.txtContent.text+"%' ";
}
}