上一篇:CYQ.Data 轻量数据层之路 使用篇一曲 裸身走天涯(十二)

 

前言说明:

本篇继续上一篇内容,本节介绍所有相关查询的使用。

主要内容提要:
1:单行数据操作 Fill 操作 GetCount操作。
2:多行数据操作 Select 操作
3:列表绑定控件操作 配合分页控件
4:多表查询及绑定 视图及自定义SQL

 

 

单行数据操作

 

一:Fill 填充方法,单行查询

方法原形:public bool Fill(object where)

示例1:直传ID

MAction action = new MAction(TableNames.Users);
if (action.Fill(888))//查询ID=888的单行数据
{
   action.SetTo(lblUserName);
   action.Close();
}

示例2:传where条件

MAction action = new MAction(TableNames.Users);
if (action.Fill("id=888 or UserName='路过秋天'"))//查询ID=888或用户名为"路过秋天"的单行数据
{
   action.SetTo(lblUserName);
   action.Close();
}

 

示例3:where条件附带order by

MAction action = new MAction(TableNames.Users);
if (action.Fill("id>888 order by id desc"))//查询ID>888的结果中取ID最大的的单行数据
{
   action.SetTo(lblUserName);
   action.Close();
}

 

 

二:GetCount 取统计总数

方法原形:public int GetCount(string where)

 

示例1:

MAction action = new MAction(TableNames.Users);
int count=action.GetCount("id>10");
action.Close();

 

 

多行数据操作

 

三:Select 多数据查询

方法原形:
1public MDataTable Select()
2public MDataTable Select(int PageIndex, int PageSize, string Where, out int RowCount)

示例1:

MAction action = new MAction(TableNames.Users);
MDataTable tabme 
= action.Select();//查询所有数据
action.Close();

示例2:

int count;//这个为返回的记录总数
MAction action = new MAction(TableNames.Users);
MDataTable tabme 
= action.Select(1,10,"id>10 order by username desc",out count);//查询id>10的10条记录[第1页,每页10条数据,结果按usename排序]
action.Close();

相关文章: