日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CYQ.Data 轻量数据层之路 自定义MDataTable绑定续章(七) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本章起,將續(xù)章講解整框架當(dāng)初的設(shè)計思路:

本章既為續(xù)章,說明我以前寫過,是的,以前我寫過內(nèi)部整個MDataTable的構(gòu)造,不過,當(dāng)初匆匆寫完后,

最后一步的實現(xiàn)MDataTable綁定GridView/DataList/Repeater還差一點,這章續(xù)上!

這里列出我以前寫過的關(guān)于構(gòu)造自定義MDataTable系列文章:

備注:以下內(nèi)容為早期所寫,文字少,代碼多,有不明之處,歡迎在文章后面留言!

?

1:CYQ.Data 輕量數(shù)據(jù)訪問層(二) 構(gòu)造數(shù)據(jù)單元(上)

2:CYQ.Data 輕量數(shù)據(jù)訪問層(三) 構(gòu)造數(shù)據(jù)單元(下)

3:CYQ.Data 輕量數(shù)據(jù)訪問層(四) 構(gòu)造數(shù)據(jù)單元列

4:CYQ.Data 輕量數(shù)據(jù)訪問層(五) 構(gòu)造數(shù)據(jù)行

5:CYQ.Data 輕量數(shù)據(jù)訪問層(六) 構(gòu)造數(shù)據(jù)表

6:CYQ.Data 輕量數(shù)據(jù)訪問層(七) 自定義數(shù)據(jù)表實現(xiàn)綁定常用的數(shù)據(jù)控件(上)

7:CYQ.Data 輕量數(shù)據(jù)訪問層(八) 自定義數(shù)據(jù)表實現(xiàn)綁定常用的數(shù)據(jù)控件(中)

8:CYQ.Data 輕量數(shù)據(jù)訪問層(九) 自定義數(shù)據(jù)表實現(xiàn)綁定常用的數(shù)據(jù)控件(下)

?

在寫完第八篇(九)之后,我們的測試結(jié)果里,并沒有完成綁定功能,我們來看一下測試代碼:

????????????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一樣,添加了兩列,然后對列賦值:

我們看一下測試的結(jié)果:

很明顯,綁定的結(jié)果亂七雜八,不是我們想要的。?

?

經(jīng)過代碼對比,發(fā)現(xiàn),我們的MDataRow得實現(xiàn)IDataRecord接口才行,于是,讓IDataRecord繼承接口,并實現(xiàn):

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
????}

?

接著瀏覽了一下,不見啥效果。

?

于是又對比了一下代碼,發(fā)現(xiàn)原來的MDataTable是采用繼承方式List<MDataRow>,

于是,把它給弄到下面來了:

?public?class?MDataTable?:?IDataReader,?IEnumerable
????{
????????
private?List<MDataRow>?_Mdr;
????????
public?List<MDataRow>?Rows
????????{
????????????
get
????????????{
????????????????
return?_Mdr;
????????????}
????????}
?????
//...下面省略N行...
}

?

?

接著小調(diào)整了一下,再次瀏覽,終于效果出來了:

?

?

?

至此,整個框架三部分中自定義MDataTable系列,就到此結(jié)束了。

?

?

備注:完整框架源碼會在本系列結(jié)束之后另開章節(jié)發(fā)布,暫時望勿激動,學(xué)習(xí)思想才是重要的。

如果在學(xué)習(xí)過程中發(fā)現(xiàn)有什么問題,歡迎留言!

版權(quán)聲明:本文原創(chuàng)發(fā)表于博客園,作者為路過秋天,原文鏈接:

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

總結(jié)

以上是生活随笔為你收集整理的CYQ.Data 轻量数据层之路 自定义MDataTable绑定续章(七)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。