CYQ.Data lightweight way to use the data layer of articles two MAction Data Query (13)

Previous: CYQ.Data lightweight way to use the data layer of an article wander naked (XII)

 

Introduction Description:

Benpian continue on the piece of content, this section describes the use of all related queries.

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

Methods prototype: public BOOL  the Fill ( Object the WHERE )    

Example 1: Direct ID

Action MAction  = new new  MAction (TableNames.Users); IF  (action.Fill ( 888 )) // query ID = single row of data 888 {    action.SetTo (lblUserName);    action.Close (); }  




Example 2: where transmission conditions

Action MAction  = new new  MAction (TableNames.Users); IF  (action.Fill ( " ID = 888 or UserName = 'passing through the autumn'")) // query name or user ID = 888 " passing autumn " one-line data {    Action .SetTo (lblUserName);    action.Close (); }  




 

Example 3: where conditions attached order by

Action MAction  = new new  MAction (TableNames.Users); IF  (action.Fill ( " ID> 888 by ID desc Order " )) // query ID> ID take maximum results in the single row of data 888 {    action.SetTo (lblUserName );    action.Close (); }  




 

 

Two: GetCount take the total number of statistics

Methods Prototype: public int  GetCount ( String the WHERE )    

 

Example 1:

MAction action  =   new  MAction(TableNames.Users);
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:

Action MAction  = new new  MAction (TableNames.Users); MDataTable tabme  =  action.Select (); // query all data action.Close ();  

Example 2:

05233222_eh4C.gif
int  COUNT; // this is the total number of records returned MAction Action  = new new  MAction (TableNames.Users); MDataTable tabme  =  action.Select ( 1 , 10 , " the above mentioned id> 10 username desc by the Order " , OUT  COUNT); // Query id> 10 records 10 [page 1, page 10 of data, the results of sorting by usename] action.Close ();
 

 

Additional information:

Select Selects all the data, the internal principle methods:
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

MAction action  =   new  MAction(TableNames.Users);
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  ]

05233222_eh4C.gif
public   void  BindData()
{
        
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

05233222_eh4C.gif
public   void  BindData()
{
        
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:

If you use the paging controls are more complex than the above usage, you can consider optimizing or abandoned the original paging controls.

 

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

05233222_eh4C.gif
public   void  BindData()
{
        
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:

05233222_eh4C.gif
public   void  BindData()
{
      
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:

In the specific use, in order to facilitate management, directly in a custom SQL statement is not so write directly in the interface, you can build a new term project management unified custom SQL.

 

Knot words:

 

After reading Benpian example, a query for this one should understand. The tie from the paging controls together to achieve is very simple.
Please use one other concern: undetermined name.

 

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274074

Guess you like

Origin blog.csdn.net/weixin_34326429/article/details/91966981