![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
MDataTable 原理解析 数据控件绑定-续篇
Principles |
|
|
| #TopicOwner |
本篇,将续篇讲解整框架当初的设计思路: 在:MDataTable 原理解析 数据控件绑定-下篇 之后,离最后一步的实现MDataTable绑定 GridView/DataList/Repeater还差一点,这章续上! 在写完上一篇之后,我们的测试结果里,并没有完成绑定功能,我们来看一下测试代码: ![]() ![]() MDataTable table=new MDataTable("myTableName"); table.Columns.Add("Url", SqlDbType.NVarChar); table.Columns.Add("Name",SqlDbType.NVarChar); MDataRow mdr = table.NewRow(); mdr[0].Value = "http://cyq1162.cnblogs.com/"; mdr[1].Value = "路过秋天"; table.Rows.Add(mdr); GridView1.DataSource = table; GridView1.DataBind();
我们像普通的DataTable一样,添加了两列,然后对列赋值: 我们看一下测试的结果: 很明显,绑定的结果乱七杂八,不是我们想要的。
经过代码对比,发现,我们的MDataRow得实现IDataRecord接口才行,于是,让IDataRecord继承接口,并实现: ![]() ![]() public class MDataRow : List<MDataCell>, IDataRecord { /// ...省略N行已有代码... #region IDataRecord 成员 int IDataRecord.FieldCount { get { return base.Count; } } bool IDataRecord.GetBoolean(int i) { return (bool)this[i].Value; } byte IDataRecord.GetByte(int i) { return (byte)this[i].Value; } long IDataRecord.GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { throw new Exception("The method or operation is not implemented."); } char IDataRecord.GetChar(int i) { return (char)this[i].Value; } long IDataRecord.GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) { return (long)this[i].Value; } IDataReader IDataRecord.GetData(int i) { throw new Exception("The method or operation is not implemented."); } string IDataRecord.GetDataTypeName(int i) { return (string)this[i].Value; } DateTime IDataRecord.GetDateTime(int i) { return (DateTime)this[i].Value; } decimal IDataRecord.GetDecimal(int i) { return (decimal)this[i].Value; } double IDataRecord.GetDouble(int i) { return (double)this[i].Value; } Type IDataRecord.GetFieldType(int i) { return this[i].Value.GetType(); } float IDataRecord.GetFloat(int i) { return (float)this[i].Value; } Guid IDataRecord.GetGuid(int i) { return (Guid)this[i].Value; } short IDataRecord.GetInt16(int i) { return (short)this[i].Value; } int IDataRecord.GetInt32(int i) { return (int)this[i].Value; } long IDataRecord.GetInt64(int i) { return (long)this[i].Value; } string IDataRecord.GetName(int i) { return (string)this[i].Value; } int IDataRecord.GetOrdinal(string name) { return (int)this[name].Value; } string IDataRecord.GetString(int i) { return (string)this[i].Value; } object IDataRecord.GetValue(int i) { return this[i].Value; } int IDataRecord.GetValues(object[] values) { return 0; } bool IDataRecord.IsDBNull(int i) { return this[i].Value == DBNull.Value; } object IDataRecord.this[string name] { get { return this[name].Value; } } object IDataRecord.this[int i] { get { return this[i].Value; } } #endregion }
接着浏览了一下,不见啥效果。
于是又对比了一下代码,发现原来的MDataTable是采用继承方式List<MDataRow>, 于是,把它给弄到下面来了: ![]() ![]() public class MDataTable : IDataReader, IEnumerable { private List<MDataRow> _Mdr; public List<MDataRow> Rows { get { return _Mdr; } } //...下面省略N行... } 接着小调整了一下,再次浏览,终于效果出来了: 至此,整个框架三部分中自定义MDataTable系列,就到此结束了。 ![]() |
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.