易截截图软件、单文件、免安装、纯绿色、仅160KB

asp.net 多字段模糊查询代码

经常用到多字段的模糊查询,上面的函数可以实现,例如strKeyWords值为“脚本之家”时
string strField = "id|className|classAdd";
string strKeyWords = this.tbxKeyWords.Text.Trim();
string strSql = dbexe.searchText("select * from class", strField, strKeyWords);
经常用到多字段的模糊查询,上面的函数可以实现,例如strKeyWords值为“脚本之家”时,可以输出:
select * from class where id like '%脚本之家%' or className like '%脚本之家%' or classAdd like '%脚本之家%'
函数:
/// <summary>
/// 根据关键字实现多字段模糊查询
/// </summary>
/// <param name="sqlStr">select * from talbe sql语句</param>
/// <param name="sqlText">判断语句条件,是一个用|隔开的字符串</param>
/// <param name="keywords">关键字</param>
public static string searchText(string strSql, string strField, string keywords)
{
StringBuilder sb = new StringBuilder(strSql);
if (strField != string.Empty)
{
sb.Append(" where ");
string[] arrKey = strField.Split('|');
for (int i = 0; i < arrKey.Length; i++)
{
sb.Append(arrKey[i] + " like '%" + keywords + "%' or ");
}
string str = sb.ToString();
//去除最后一个"or"
if (str.IndexOf("or") >= 0)
{
return str.Remove(str.LastIndexOf("or"));
}
return str;
}
return strSql;
}
详细出处参考:http://www.jb51.net/article/15251.htm


相关文档:

asp.net 中实现页面每隔一分钟刷新一次的效果

在Global.asax
需要回顾的知识点是 线程 和  文本文件的读写。
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
    string logpath;
    Thread thread; ......

Parameter Queries in ASP.NET with MS Access

Parameter Queries in ASP.NET with MS Access
A selection of code samples for executing queries against MS Access using parameters.
Making use of the ASP.NET 2.0 datasource controls is fine, but it is important to understand how to manually create data access code. Best practice dictates that, at t ......

ASP.NET自定义错误页面

ASP.NET 提供三种用于在出现错误时捕获和响应错误的主要方法:Page_Error 事件、Application_Error 事件以及应用程序配置文件 (Web.config)。
如果您不调用 Server.ClearError 或者捕获 Page_Error 或 Application_Error 事件中的错误,则将根据 Web.config 文件的 <customErrors> 部分中的设置处理错误。在 <cus ......

ASP.net的身份验证方式有哪些?分别是什么原理?

Windows 身份验证提供程序 提供有关如何将 Windows 身份验证与 Microsoft Internet 信息服务 (IIS) 身份验证结合使用来确保 ASP.NET 应用程序安全的信息。 Forms 身份验证提供程序 提供有关如何使用您自己的代码创建应用程序特定的登录窗体并执行身份验证的信息。使用 Forms 身份验证的一种简便方法是使用 ASP.NET 成员资格 ......

asp.net 页面延时五秒,跳转到另外的页面

asp.net 页面延时五秒,跳转到另外的页面的实现代码。
--前台
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Successed.aspx.cs" Inherits="Biz_Order_Successed" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xht ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号