简单or条件查询(没有其他and条件干扰,代码不需要建组查询)
2015-04-06 09:28:16 访问(1253) 赞(0) 踩(0)
生成和输出的SQL语句
select top 10 t.ID, t.TheName, t.ClassId,
t.CreateTime, t.UpdateTime from UTB_EXAM_STUDENT t where t.TheName like '李'+'%' or t.TheName like '陈'+'%' order by
t.ID asc
@tp3 = '李'
@tp4 = '陈'
select top 10 t.ID, t.TheName, t.ClassId,
t.CreateTime, t.UpdateTime from UTB_EXAM_STUDENT t where t.TheName like @tp3+'%' or t.TheName like @tp4+'%' order by
t.ID asc
@tp3 李 String Input SqlParameter
@tp4 陈 String Input SqlParameter
关键代码
iq.AddIQueryItemWithEntityFieldInfo
(
entity._TheName,
SlowX.Core.Enums.SqlLink.EmSqlLink.Like_,
"李"
);
iq.AddIQueryItemWithEntityFieldInfo
(
SlowX.Core.Enums.SqlConditionLink.EmSqlConditionLink.or,
entity._TheName,
SlowX.Core.Enums.SqlLink.EmSqlLink.Like_,
"陈"
);
代码写法
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SlowX.DAL.Helpers;
using SlowX.Core.ICoreClasses;
using System.Data;
using SlowX.Functions.Functions;
using SlowX.Core.CoreClasses;
public partial class ExamSQL : System.Web.UI.Page
{
protected string strResult = "";
protected void Page_Load(object sender, EventArgs e)
{
DataBindTheContorls(null);
}
#region 操作
/// <summary>
///
/// </summary>
/// <param name="xdbHelper"></param>
protected void DataBindTheContorls(DBHelper xdbHelper)
{
string theResult = null;
bool bIsCreate = true;
if (xdbHelper == null)
{
xdbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
}
else
{
// 没有打开链接 //
bIsCreate = xdbHelper.IsNotOpen();
}
try
{
if (bIsCreate)
xdbHelper.OpenDBHelper();
// 获得数据库操作的实体 //
SlowX.ExamLib.Business.UTB_EXAM_STUDENT
bll
=
SlowX.ExamLib.Business.UTB_EXAM_STUDENT.instance;
// 创建SQL操作的载体 //
SlowX.ExamLib.Entity.UTB_EXAM_STUDENT
entity
=
new SlowX.ExamLib.Entity.UTB_EXAM_STUDENT();
// 查询条件 //
IQueryDriver iq = entity;
IOrderByDriver iorder = entity;
iorder.AddIOrderByItemWithEntityFieldInfo
(
entity._ID,
SlowX.Core.Enums.OrderBy.EmOrderBy.ASC
);
iq.AddIQueryItemWithEntityFieldInfo
(
entity._TheName,
SlowX.Core.Enums.SqlLink.EmSqlLink.Like_,
"李"
);
iq.AddIQueryItemWithEntityFieldInfo
(
SlowX.Core.Enums.SqlConditionLink.EmSqlConditionLink.or,
entity._TheName,
SlowX.Core.Enums.SqlLink.EmSqlLink.Like_,
"陈"
);
DataSet ds = bll.PageList(0, 10, entity, xdbHelper);
theResult =
@"<textarea name=""TextBox1"" rows=""2"" cols=""20"" id=""TextBox1"" style=""height:400px;width:99%;"">"
+ bll.BuildSqlPageList(0, 10, entity, xdbHelper)
+ "</textarea>";
theResult += "<br /><br />";
theResult += DataSetSlowXFunctions.DataSetToHtmlTable(ds, true);
if (bIsCreate)
xdbHelper.EndDBHelper();
}
catch (Exception err)
{
if (bIsCreate)
xdbHelper.TranDBHelper();
throw err;
}
finally
{
if (bIsCreate)
xdbHelper.FinallyDBHelper();
}
strResult = theResult;
}
#endregion 操作
}
标签:
简单or条件查询(没有其他and条件干扰,代码不需要建组查询) 


上一条:
下一条:
相关评论
发表评论