CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
CYQ.Data 数据框架 使用篇五 MProc 存储过程与SQL
Guide |
|
|
| #TopicOwner |
本节内容: 本篇继续上一篇内容,本节介绍MProc 类的相关操作。 1:MProc 存储过程操作 2:MProc SQL执行操作 一:构造函数 方法原型: public MProc(object procNamesEnum) public MProc(object procName, string conn) 说明: 构造函数和MAction用法一致,相关操作可参数MAction。 示例1:传入存储过程名称 //传入存储过程名称 默认取配置项Conn的数据库链接 MProc proc = new MProc(ProcNames.GetUserList);//通过枚举传入 示例2:传入存储过程名称及自定义数据库链接 //传入数据库新的数据库链接 配置项Conn MProc proc = new MProc("GetUserList","ChatConn"); //传入数据库新的数据库链接 直接链接字符串 MProc proc = new MProc("GetUserList","Server=.;database=Chat;uid=sa;pwd=xxxxx"); //多数据库下用约定名称 取自ChatConn配置项的链接 MProc proc = new MProc(P_ChatEnum.GetUserList); 示例3:传入SQL语句 说明:仅在V1.5版本以上支持。 //执行自定义SQL 语句 默认取自Conn配置项数据库链接 MProc proc = new MProc("select * from Users"); //执行自定义SQL 语句 取自ChatConn配置项数据库链接 MProc proc = new MProc("select * from Users","ChatConn"); 二:参数化操作 方法原型: public void Set(object paraName, object value) public void Set(object paraName, object value,SqlDbType sqlDbType) public MProc SetCustom(object paraName, ParaType paraType, object value) public void Clear() 示例1: //为存储过程或参数化SQL语句的设置参数 proc.Set(GetUserList.ID, 888);//枚举方式传递 示例2: proc.Set(Users.ID, 888,SqlDbType.Int);//比上个示例多加了个参数。 示例3: proc.Clear();//清除所有Set的参数。 三:方法操作 方法原型: public MDataTable ExeMDataTable() //列表查询 public List<MDataTable> ExeMDataTableList()//查询多个列表 public int ExeNonQuery() //添加/更新/删除 public T ExeScalar<T>() //返回首行首列单个值 示例1: MDataTable table = proc.ExeMDataTable();//执行返回MDataTable 示例2: int result = proc.ExeNonQuery();//添加、更新、删除操作,返回受影响的行数。 示例3: string result = proc.ExeScalar<string>();//执行语句,返回首行首列的值。 四:返回值与链接关闭 方法原型: public int ReturnValue public void Close() 示例1: MDataTable table= proc.ExeMDataTable(); int value = proc.ReturnValue;//执行的如果是存储过程,取返回值,通过是记录总数。 示例:手动型关闭链接 MProc proc = new MProc(ProcNames.GetList); MDataTable table= proc.ExeMDataTable(); int value = proc.ReturnValue; proc.Close();//执行完后关闭数据库链接 五:一个完整示例 示例: 使用示例:
实例化: using(MProc proc = new MProc(ProcNames.GetList)) { 添加参数: proc.Set(GetList.ID, 10); proc.SetCustom("ReturnValue", ParaType.ReturnValue); proc.SetCustom("ReturnValue", ParaType.OutPut);
获取列表: MDataTable table = proc.ExeMDataTable(); 取返回值: int count=proc.ReturnValue;
object outPutValue=proc.OutPutValue; 绑定控件: table.Bind(GridView1); } |
游客[注册][121.9.14.*]2014/8/15 14:50:28 | #2 | |
public static int ProcNonQuery(string sSql) { int iReturn; using (MProc mp = new MProc(sSql)) { iReturn = mp.ExeNonQuery(); mp.Close(); } return iReturn; } 执行删表操作失败!ProcNonQuery("Drop table [test1]"); 请教如何调用,数据库为access reply: 早期版本对SQL进行严格的限制,所以不能操作删除表操作,最新版本放松了限制,可以执行任意的语句了。 |
游客[注册][125.77.202.*]2014/5/26 16:33:22 | #1 | |
ALTER procedure [dbo].[Proc_Common_GetDataByPage] ( @TableName nvarchar(500), --数据表名称 @Fields nvarchar(500)='*', --查询的字段列表 @StrWhere nvarchar(1000)='', --查询条件 @StrOrder nvarchar(100)='', --排序字段列表 @PageIndex int=1, --当前页指针 @PageSize int=10, --每页显示的记录数 @RecordCount int=0 output --返回总记录数 ) mproc执行存储过程如何返回RecordCount有值,用proc.ReturnValue返回怎么都是0 reply: 应该取proc.OutPutValue |
Post Comment
Bulletin
Article Search
Categories
- Platform for dynamic (20)
- Feedback (9)
- Guide (33)
- Principles (19)
- Project-Case (8)
- Business & Buy (2)
- Technology exchange (45)
New Article
- CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]
- CYQ.Data Components Getting Started Guide [Part 4]-[MAction Insert Delete Update]
- CYQ.Data Components Getting Started Guide [Part 3]-[MAction Get And Set Value]
- CYQ.Data Components Getting Started Guide [Part 2]-[MAction Data Query- Fill And Select]
- CYQ.Data Components Getting Started Guide [Part 1]
New Comment
- When some one searches for his necessary thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.
- This is my first time pay a quick visit at here and i am in fact happy to read everthing at alone place.
- I truly appreciate this blog article.Really thank you! Cool.
- please pay a visit to the web sites we follow, like this one particular, as it represents our picks in the web
- Really enjoyed this post.Really thank you!
- Really enjoyed this article.Really looking forward to read more. Great.
- poker bonuses What are the norms of copyright of web content? How as it different from Patent?
- Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a fragment of your post to my site?
- This website was how do I say it? Relevant!! Finally I ave found something that helped me. Cheers!
- I was reading through some of your content on this internet site and I believe this web site is very informative ! Continue posting.