CYQ.Data 轻量数据层之路 自定义MDataTable绑定续章(七)

本章起,将续章讲解整框架当初的设计思路:

本章既为续章,说明我以前写过,是的,以前我写过内部整个MDataTable的构造,不过,当初匆匆写完后,

最后一步的实现MDataTable绑定GridView/DataList/Repeater还差一点,这章续上!

这里列出我以前写过的关于构造自定义MDataTable系列文章:

备注:以下内容为早期所写,文字少,代码多,有不明之处,欢迎在文章后面留言!

 

1:CYQ.Data 轻量数据访问层(二) 构造数据单元(上)

2:CYQ.Data 轻量数据访问层(三) 构造数据单元(下)

3:CYQ.Data 轻量数据访问层(四) 构造数据单元列

4:CYQ.Data 轻量数据访问层(五) 构造数据行

5:CYQ.Data 轻量数据访问层(六) 构造数据表

6:CYQ.Data 轻量数据访问层(七) 自定义数据表实现绑定常用的数据控件(上)

7:CYQ.Data 轻量数据访问层(八) 自定义数据表实现绑定常用的数据控件(中)

8:CYQ.Data 轻量数据访问层(九) 自定义数据表实现绑定常用的数据控件(下)

 

在写完第八篇(九)之后,我们的测试结果里,并没有完成绑定功能,我们来看一下测试代码:

复制代码
ExpandedBlockStart.gif
            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继承接口,并实现:

复制代码
ExpandedBlockStart.gif
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>,

于是,把它给弄到下面来了:

复制代码
ExpandedBlockStart.gif
 public class MDataTable : IDataReader, IEnumerable
    {
        
private List<MDataRow> _Mdr;
        
public List<MDataRow> Rows
        {
            
get
            {
                
return _Mdr;
            }
        }
     
//...下面省略N行...
}
复制代码

 

 

接着小调整了一下,再次浏览,终于效果出来了:

 

 

 

至此,整个框架三部分中自定义MDataTable系列,就到此结束了。

 

 

备注:完整框架源码会在本系列结束之后另开章节发布,暂时望勿激动,学习思想才是重要的。

如果在学习过程中发现有什么问题,欢迎留言!

版权声明:本文原创发表于博客园,作者为路过秋天,原文链接:

http://www.cnblogs.com/cyq1162/archive/2010/08/24/1806300.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540946.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php 文字超出画布,input实现文字超出省略号(代码示例)

本篇文章给大家带来的内容是关于input实现文字超出省略号(代码示例)&#xff0c;有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对你有所帮助。input实现文字省略号功能普通元素实现文字超出宽度自动变成省略号非常简单&#xff0c;给元素加个宽度&…

c++ stl stack_C ++ STL中的stack :: top()函数

c stl stackPrototype: 原型&#xff1a; stack<T> st; //declarationT st.top();Parameter: 参数&#xff1a; No parameter passedReturn type: T //data type 返回类型&#xff1a; T //数据类型 Header file to be included: 包含的头文件&#xff1a; #include …

排序算法系列:插入排序算法

概述 直接插入排序&#xff08;Straight Insertion Sort&#xff09;的基本操作是将一个记录插入到已经排好序的有序表中&#xff0c;从而得到一个新的、记录数增1的有序表。 – 《大话数据结构》 版权说明 著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载…

php点击复制按钮到我的粘贴板,js实现点击复制当前文本到剪贴板功能(兼容所有浏览器)...

最近做项目时&#xff0c;在网站框架搭建过程&#xff0c;有一个功能需要实现复制文本到剪贴板&#xff0c;相信这个功能很常用&#xff0c;但是对于不常写JS代码的我来说是一个比较大的挑战&#xff0c;回想以前做过的一个站点&#xff0c;使用window.clipboardData实现复制到…

算法导论 算法_算法导论

算法导论 算法Algorithms are an integral part of the development world. Before starting coding of any software first an effective algorithm is designed to get desired outputs. In this article, we will understand what are algorithms, characteristics of algor…

[Phonegap+Sencha Touch] 移动开发77 Cordova Hot Code Push插件实现自己主动更新App的Web内容...

原文地址&#xff1a;http://blog.csdn.net/lovelyelfpop/article/details/50848524 插件地址&#xff1a;https://github.com/nordnet/cordova-hot-code-push 以下是我对GitHub项目readme的翻译 ——————————————————————————————————————…

java 如何重写迭代器,如何用Java按需定制自己的迭代器

编写自己的迭代器的流程是&#xff1a;首先实现Iterable接口&#xff0c;进而实现该接口中的Iterator iterator()方法&#xff0c;该方法返回接口Iterator&#xff0c;Iterator接口中封装了next&#xff0c;hasnext&#xff0c;remove等方法。实现了Iterable接口的类能够通过fo…

count函数里加函数_PHP count()函数与示例

count函数里加函数PHP count()函数 (PHP count() function) "count() function" is used to get the total number of elements of an array. “ count()函数”用于获取数组元素的总数。 Syntax: 句法&#xff1a; count(array, [count_mode])Here, 这里&#xff0…

php整合支付宝,Thinkphp5.0整合支付宝在线下单

thinkphp5.0支付宝在线支付下单整个流程&#xff0c;包括创建订单、支付成功回调更新订单状态、最终跳转到商户订单详情页查看演示下载资源&#xff1a;17次 下载资源下载积分&#xff1a;998积分支付宝在线支付控制器代码 public function alipay() {//发起支付宝支付$order_n…

python函数示例_PHP closeir()函数与示例

python函数示例PHP Closedir()函数 (PHP closedir() function) The full form of closedir is "Close Directory", the function closedir() is used to close an opened directory. Closedir的完整格式为“ Close Directory” &#xff0c; 函数closedir()用于关闭打…

java宋江,Java编程内功-数据结构与算法「单链表」,

package com.structures.linkedlist;public class SingleLinkedListDemo {public static void main(String[] args) {HeroNode heroNode1 new HeroNode(1, "宋江", "及时雨");HeroNode heroNode2 new HeroNode(2, "卢俊义", "玉麒麟"…

智能家居逐渐融入AI技术 向大众市场扩张仍需时间

虽然智能家居变得越来越普遍&#xff0c;并且大众认知度越来越高&#xff0c;但是在这一技术变得像智能手机一样无处不在之前&#xff0c;OEM和服务提供商仍然有很长的路要走。 在2016年11月在硅谷举行的智能家居峰会上&#xff0c;代表们听到了来自整个价值链上的声音&#xf…

python 示例_Python使用示例设置add()方法

python 示例设置add()方法 (Set add() Method) add() method is used to add an element to the set, the method accepts an element and adds the elements to this set. add()方法用于将元素添加到集合中&#xff0c;该方法接受元素并将元素添加到该集合中。 Note: If the …

php怎么引用表单元素,表单元素:最全的各种html表单元素获取和使用方法总结...

表单是网页与用户的交互工具&#xff0c;由一个元素作为容器构成&#xff0c;封装其他任何数量的表单控件&#xff0c;还有其他任何元素里可用的标签&#xff0c;表单能够包含、、、、、等表单控件元素。表单元素有哪些呢&#xff1f;它包含了如下的这些元素&#xff0c;输入文…

数据中心部署气流遏制系统需要考虑的十大要素

数据中心气流遏制策略能够大幅提高传统数据中心制冷系统的可预测性和效率。事实上&#xff0c;绿色网格组织&#xff08;The Green Grid&#xff09;将气流管理策略称作“实施数据中心节能计划的起点”。但是&#xff0c;大多数已有数据中心由于受各种条件的制约&#xff0c;只…

JAVA语言异常,Java语言中的异常

1、异常分类从产生源头来看&#xff0c;Java语言中的异常可以分为两类&#xff1a;JVM抛出的异常。比如&#xff1a;访问null引用会引发NullPointerException&#xff1b;0作为除数&#xff0c;如9/0&#xff0c;JVM会抛出ArithmeticException&#xff1b;内存消耗完&#xff0…

使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法

新建generatorConfig.xml和build_mybatis.xml&#xff1a; jar下载 <dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.2</version></dependency> <depe…

java bitset_Java BitSet or()方法与示例

java bitsetBitSet类或()方法 (BitSet Class or() method) or() method is available in java.util package. or()方法在java.util包中可用。 or() method is used to perform logical OR between this BitSet and the given BitSet(bs). This BitSet is updated when either t…

matlab 细化函数,MATLAB图像处理工具箱函数(细化篇).doc

MATLAB图像处理工具箱函数(细化篇)第3章 MATLAB数字图像处理工具箱3.1 MATLAB图像预处理3.1.1 图像处理的基本操作1. 读入并显示一幅图像clear %清除所有的工作平台变量close all %关闭已打开的图形窗口Iimread (pout.tif); %读取图像pout.tif(该图像是图像处理工具箱自带的图像…

STM32启动解析

启动方式对的不同下载模式 STM32可以通过BOOT引脚的配置&#xff0c;来选择不同的启动模式------对应不同的下载方式。 仿真器下载—— 内部FLASH的启动方式 串口下载 —— 系统存储器的启动方式 内部SRAM一般不用&#xff0c;不讲 启动过程 以内部FLASH的启动方式为例&am…