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.pswp.cn/news/540946.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540946.shtml
英文地址,請注明出處:http://en.pswp.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…