![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
MDataTable属性RecordsAffected新应用:WebService与Json交互的记录总数
Technology exchange |
|
|
| #TopicOwner |
最近CYQ.Data v5版本中添加了一个新功能,先说下需求的来源: 1:有一台服务器,以WebService方式提供数据。 2:有客户端,调用远程服务器WebService的数据,然后显示表格并带有分页功能。 基于以前版本,最佳应用方式为: 1:WebService 端: 通过MAction,查询出表(MDataTable),再调用ToJson返回json输出。 2:客户端: 通过调用调用远程的方法,接收返回的json字符串,然后用MDataTable.LoadFromJson方法,加载还原为表格,然后绑定到列表控件即可。 使用起来是相当方便简洁的,但是却缺少了一个重要的信息,通常分页的时候,需要知道多一个记录总数。 对于旧版本,返回的参数,需要自己再附加多一个记录总数返回。 为了使使用更简单,本人进行了以下的改进: 1:把调用Select分页查询后,把记录总数赋值给MDataTalle属性RecordsAffected。 2:对于ToJson方法输出,把记录总数也一并集在json中。 3:MDataTable.LoadFromJson时,可以还原记录总数到RecordsAffected属性。 有了以上改进,只需要简单的以下代码就可以解决了: 以下为伪代码示例: 1:服务端代码,根据分页参数输出表的Json: [WebService] public string GetTableJson(int pageIndex,int pageSize,string tableName) { MDataTable dt; using (MAction action = new MAction(tableName)) { dt = action.Select(pageIndex, pageSize, "id>10"); } return dt.ToJson(); } 2:客户端,调用WebService: public void GetTableJson() { string json = WebServer.GetTableJson(1,10,"Users");//调用远程WebService,获取表数据 MDataTable dt = MDataTable.LoadFromJson(json);//从json还原为表格 dt.Bind(GridView1);//直接绑定到列表控件 Page1.RecordCount = dt.RecordsAffected;//设置分页控件的记录总数 } 以上就是CYQ.Data V5版本MDataTable的RecordsAffected属性的应用场景之一。 刚折腾了框架的示例源码: ![]() ![]() |
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.