CYQ.Data 数据层框架

CYQ.Data 是一款由路过秋天创作的支持多数据库应用[Txt,Xml,Access,MSSQL,Oracle,SQLite,MySql]的底层数据库操作类库,使用本类库可以轻松快速开发项目。

CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]

快速使用帮助 | | | 发表日期 :2011-7-2 20:19:22#楼主  

In this section:

continue on a content, this section describes MProc class-related operations.

 1: MProc execute stored procedure

 2: MProc execute SQL operations

I:Constructor

Method Prototype :
 
public MProc(object  procNamesEnum)

public MProc(object  procName, string conn)

Description:

Constructor and MAction usage of the relevant operating parameters can be MAction.

Example 1:Pass stored procedure name

//Stored procedure name passed in the default configuration items to take Conn database link
MProc proc
= new MProc(ProcNames.GetUserList);//Passing through the enumeration

Example 2:Pass stored procedure name and custom database link

 
//Into the database a new database link configuration items Conn
 
MProc proc = new MProc("GetUserList","ChatConn");

//Into the database directly link the new database link string
MProc proc = new MProc("GetUserList","Server=.;database=Chat;uid=sa;pwd=xxxxx");

//Multi-use agreement under the name of the database configuration items from ChatConn links
MProc proc = new MProc(P_ChatEnum.GetUserList);

Example 3:Pass SQL statement

Note: Only supported in V1.5 version of the above.
/ / Execute custom SQL statement, the default configuration items database link from Conn
MProc proc = new MProc("select * from Users");

/ / Execute custom SQL statements from the configuration items database link ChatConn

MProc proc = new MProc("select * from Users","ChatConn");

II:Parameterization

Method Prototype :
 
public void Set(object  paraName, object  value)

public void Set(object  paraName, object
  value,SqlDbType sqlDbType)

public void
Clear()

Example 1:

//As stored procedures or parameterized SQL statement to set parameters
proc.Set(GetUserList.ID, 888);//Enumeration method to pass

Example 2:

proc.Set(Users.ID, 888,SqlDbType.Int);//More than in the last example of a parameter.

Example 3:

proc.Clear();//Clear all Set parameters.

III:Execute Method Operation

Method Prototype :
 
public MDataTable ExeMDataTable() / / List of query

public int
ExeNonQuery() / / Add / Update / Delete

public T ExeScalar<T>
() / / Return a single value of the first row first column

Example 1:

MDataTable table = proc.ExeMDataTable();// return MDataTable

Example 2:

int result = proc.ExeNonQuery();//Insert, update, delete, return the number of rows affected.

Example 3:

string result = proc.ExeScalar<string>();//Statement is executed, returns the first row first column value.

IV:ReturnValue and DataBase Close

Method Prototype :

public int
ReturnValue

public void
Close()

Example 1:

MDataTable table= proc.ExeMDataTable();
int value = proc.ReturnValue;//
If the stored procedure is executed, the return value obtained by the total number of records.

Example 2:Close manually

MProc proc = new MProc(ProcNames.GetList);
MDataTable table
=
proc.ExeMDataTable();
int value =
proc.ReturnValue;
proc.Close();
//Close the database links after the implementation of

V:A complete example

Example

Examples of use:

Instantiation:            using(MProc proc
= new MProc(ProcNames.GetList))
                                        {
Add parameters:                      proc.Set(GetList.ID,
10
);
Access list:                              MDataTable table
= proc.ExeMDataTable();
Take the return value:           int count=proc.ReturnValue;

Bound control:                       
table.Bind(GridView1);
                                        }

Chinese version of the link:http://www.cyqdata.com/cyqdata/article-detail-415

More tutorials:

 



发表评论

论坛公告

    数据框架 CYQ.Data QQ群:
    1:6033006
    2:90594529
    3:129551677
    4:113108920

    使用本框架进行开发,入门简单,开发效率高,性能优越,更有详尽的API文档,有相关的使用帮助文章、示例文章、更甚有相关的视频教程及辅助工具。 关键还是免费与开源,实在是居家旅行、项目开发、学习研究的必备良品!!!!!!
    框架下载:下载中心

帖子搜索