![]() | 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 数据框架 版本发布 V2.5
Platform for dynamic |
|
|
| #TopicOwner |
前言:
一直都是发布版本才写文章,这次为抢先体验版本[V2.5]做一下简单的功能介绍
以下进行功能更新说明[相比V2.0版本]: 1:修正DebugInfo属性在异常发生时无法取得操作语句的问题
2:MAction增加Bind方法可以轻松绑定DropDownList等控件 3:MDataTable增加ToList<T>泛型方法 4:修正MDataTable的ToJson方法 5:增加CYQ.Data.Orm.OrmBase抽象基类[为传统实体型ORM提供支持]
接着为功能进行示例操作,所有编写代码均放在Page_Load中:
一:调试信息输出
1:编写代码如下 MAction action = new MAction(TableNames.Users); if (!action.Fill("产生错误")) { Response.Write(action.DebugInfo); }
2:于是默认抛出异常
3:修改配置文件,启用日志记录,则不再抛异常 <appSettings><add key="IsWriteLog" value="true"/>appSettings>
4:这时候再运行,输出了DebugInfo 说明: 从上图可以看到所有数据库已执行的SQL语句,非常方便进行调试。
二:MAction的Bind功能演示
1:编写代码如下 new MAction(TableNames.Users).Bind(ddlUserName).Close(); 说明: ![]() ![]() Bind方法有三个重载方法:
public MAction Bind(object control) public MAction Bind(object control, string where) public MAction Bind(object control, string where, object text, object value) 说明:前面两个方法按约定取[控件id(去掉三个字母前缀)做为text字段+ID为value字段] control参数支持继承ListControl的所有控件如:DrowDownList/CheckBoxList/RadioButtonList等
2:演示结果如图
3:对应的html ![]() ![]() <select name="ddlUserName" id="ddlUserName"> <option value="1">路过秋天option> <option value="2">狼Robotoption> <option value="3">深蓝医生option> <option value="4">天才123option> <option value="5">天才123444option> <option value="9">goodboyoption> <option value="17">goodboyoption> select>
三:MDataTable的ToList
1:增加实体Users ![]() ![]() public class UsersDemo { private int _ID; public int ID { get { return _ID; } set { _ID = value; } } private string _Username; public string UserName { get { return _Username; } set { _Username = value; } } private string _Password; public string Password { get { return _Password; } set { _Password = value; } } private DateTime _CreateTime; public DateTime CreateTime { get { return _CreateTime; } set { _CreateTime = value; } } }
2:编写代码如下 ![]() ![]() MAction action = new MAction(TableNames.Users); MDataTable table = action.Select(); action.Close(); List<UsersDemo> listDemo = table.ToList<UsersDemo>();//转成泛型实体列表 gvUsers.DataSource = listDemo; gvUsers.DataBind();
3:演示结果
四:MDataTable的ToJson方法演示
1:编写代码如下 using (MAction action = new MAction(TableNames.Users)) { Response.Write(action.Select().ToJson()); }
2:输出结果 ![]() ![]() {"count":"7","error":"","success":"true", "data":[{"ID":"1","UserName":"路过秋天","Password":"http://cyq1162.cnblogs.com","CreateTime":"2010-8-21 14:01:07"}, {"ID":"2","UserName":"狼Robot","Password":"http://cyq1162.cnblogs.com","CreateTime":"2010-8-21 14:04:57"}, {"ID":"3","UserName":"深蓝医生","Password":"http://cyq1162.cnblogs.com","CreateTime":"2010-8-21 14:05:44"}, {"ID":"4","UserName":"天才123","Password":"http://cyq1162.cnblogs.com","CreateTime":"2010-9-4 14:57:28"}, {"ID":"5","UserName":"天才123444","Password":"http://cyq1162.cnblogs.com","CreateTime":"2010-9-4 15:00:20"}, {"ID":"9","UserName":"goodboy","Password":"abc","CreateTime":"2010-10-13 16:51:58"},{"ID":"17","UserName":"goodboy","Password":"333","CreateTime":"2010-10-13 17:09:34"}]}
五:支持传统ORM访问方式示例演示 说明:本功能由 圣殿骑士 留言引发。
1:实体继承CYQ.Data.Orm.OrmBase public class UsersDemo :CYQ.Data.Orm.OrmBase { public UsersDemo() { base.SetInit(this, "Users", "Conn"); } //...省略下面积的实体属性 } 说明: 1:需要继承基类:CYQ.Data.Orm.OrmBase 2:需要在构造函数初始化base.SetInit(this,"表名","数据库链接字符串/链接配置名称/为空时默认为Conn配置项");
2:编写代码演示[添加/更新/删除/查询/列表查询与绑定] ![]() ![]() protected void Page_Load(object sender, EventArgs e) { UsersDemo myUser = new UsersDemo(); myUser.UserName = "路过秋天-博客园"; myUser.Password = "http://cyq1162.cnblogs.com"; myUser.Insert();//插入一条数据 myUser.Password = "我更改了密码"; myUser.Update(); myUser.Delete(17);//删除id=17的数据 if (myUser.Fill(9))//单数据填充 { Response.Write(myUser.UserName); } myUser.Select().Bind(gvUsers);//查询Users表所有数据并绑定到GrivdView控件 List<UsersDemo> entityList = myUser.Select().ToList<UsersDemo>(); gvUsers2.DataSource = entityList;//转泛型再绑定 gvUsers2.DataBind(); }
3:结果演示
a:原来表数据
b:操作后结果数据
结言: 谢谢大家支持与喜欢,吾将持续做好框架更新工作继续前进。
![]() |
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.