Previous: CYQ.Data lightweight way to use the data layer of an article wander naked (XII)
Introduction Description:
Main Summary:
1: single data manipulation operations GetCount Fill operation.
2: Select multiple rows of data manipulation operations
3: List-bound controls operate with paging controls
4: multi-table queries and bind the views and custom SQL
Single-line data manipulation
A: Fill filling method, single-row query
Example 1: Direct ID
Example 2: where transmission conditions
Example 3: where conditions attached order by
Two: GetCount take the total number of statistics
Example 1:
int count = action.GetCount( " id>10 " );
action.Close();
Multiple rows of data operations
Three: Select multiple data query
1 : public MDataTable Select()
2 : public MDataTable Select( int PageIndex, int PageSize, string Where, out int RowCount)
Example 1:
Example 2:
Additional information:
public MDataTable Select ()
{
int COUNT;
return Select ( 0 , 0 , "" , OUT COUNT);
}
List bind operation
Four: Bind GridView / DataList / Repeater
Example 1: All direct binding inquiry
MDataTable table = action.Select();
action.Close();
gvUsers.DataSource = table;
gvUsers.DataBind();
Example 2: with pagination controls combat Post article pagination controls bind [Download: CYQ.Data road data layer of lightweight bug feedback, optimization tips, download the latest frame ]
{
int count;
MAction action = new MAction(TableNames.Users);
MDataTable table = action.Select(Pager1.PageIndex,Pager1.PageSize, " id>10 " , out count);
action.Close();
gvUsers.DataSource = table;
gvUsers.DataBind();
Pager1.Count = count; // 设置记录总数
Pager1.BindName = " BindData " ; // 绑定方法名称
}
Example 3: Get with the other way paging controls bind
{
int count;
MAction action = new MAction(TableNames.Users);
MDataTable table = action.Select(Pager1.PageIndex,Pager1.PageSize, " id>10 " , out count);
action.Close();
gvUsers.DataSource = table;
gvUsers.DataBind();
Pager1.Count = count;
}
Description:
Multi-table queries and bind
Five: View mode
Example 1: Table and operate the same, the only difference is the name of the table name into view
{
int count;
MAction action = new MAction(ViewNames.V_Users);
MDataTable table = action.Select(Pager1.PageIndex,Pager1.PageSize, " id>10 " , out count);
action.Close();
gvUsers.DataSource = table;
gvUsers.DataBind();
Pager1.Count = count;
Pager1.BindName = " BindData " ;
}
Six: Customize multi-table structure SQL statements
Example 1:
{
string customTable = " (select u.*,m.Body from Users u left join Message m on u.ID=m.UserID) v " ;
int count;
MAction action = new MAction(customTable);
MDataTable table = action.Select(Pager1.PageIndex,Pager1.PageSize, " id>10 " , out count);
action.Close();
gvUsers.DataSource = table;
gvUsers.DataBind();
Pager1.Count = count;
Pager1.BindName = " BindData " ;
}
Description:
Knot words:
Reproduced in: https: //my.oschina.net/secyaher/blog/274074