指定字段进行Count操作

2015-04-06 09:23:23  访问(1610) 赞(0) 踩(0)

生成和输出的SQL语句

select count(t.ID) from UTB_EXAM_STUDENT t where t.TheName like '李'+'%' 

@tp2 = '李'


select count(t.ID) from UTB_EXAM_STUDENT t where t.TheName like @tp2+'%' 

@tp2 	 李 	 String 	 Input 	 SqlParameter




关键代码

 // 指定字段Count //
            entity.countEntityFieldInfo = entity._ID;


代码写法

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();

            // 指定字段Count //
            entity.countEntityFieldInfo = entity._ID;

            
            // 查询条件 //
            IQueryDriver iq = entity;

            // TheName = '一班'
            iq.AddIQueryItemWithEntityFieldInfo
                (
                    entity._TheName,
                    SlowX.Core.Enums.SqlLink.EmSqlLink.Like_,
                    "李"
                );

            int iCount = bll.Count(entity, xdbHelper);


            theResult =
                @"<textarea name=""TextBox1"" rows=""2"" cols=""20"" id=""TextBox1"" style=""height:400px;width:99%;"">"
                + bll.BuildSqlCount( entity, xdbHelper)
                + "</textarea>";

            theResult += "<br /><br />";

            theResult += iCount.ToString();


            if (bIsCreate)
                xdbHelper.EndDBHelper();

        }
        catch (Exception err)
        {
            if (bIsCreate)
                xdbHelper.TranDBHelper();

            throw err;
        }
        finally
        {
            if (bIsCreate)
                xdbHelper.FinallyDBHelper();
        }

        strResult = theResult;
    }

    #endregion 操作

}




标签:指定字段进行Count操作 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)