Since this chapter, the chapter continued to explain the whole framework of the original design ideas:
This chapter not only for the chapter continued, that I've written, yes, before I wrote the whole MDataTable of the internal structure, however, after the rush had finished,
The final step in the realization of MDataTable bind GridView / DataList / Repeater also came close, this chapter continue on!
Here are I've written about the construction of custom MDataTable series:
Note: The following content is written earlier, less text, more than the code, there is the unknown, welcomed the message later in the article!
. 1: CYQ.Data lightweight data access layer (b) construct data units (on)
2: CYQ.Data Lightweight Data Access Layer (iii) construct data units (at)
. 3: CYQ.Data Lightweight Data Access Layer (D) configuration data cell columns
. 4: CYQ.Data Lightweight Data Access Layer (E) Constructs a data line
. 5: CYQ.Data Lightweight Data Access Layer (VI) is configured Datasheet
After finished eighth chapter (IX), our test results, the binding functionality is not complete, we look at the test code:
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();
We like normal, like DataTable, adds two, then the column assignment:
We look at the test results:
Obviously, the result of the binding of chaos mixed seven eight, not what we want.
After the code comparison and we found that our MDataRow have to realize IDataRecord interfaces for the job, so let IDataRecord inherited interface and implementation:
{
/// ...省略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
}
Then browse a bit, see what effect.
So I compared the code and found that the MDataTable is the use of inheritance List <MDataRow>,
So, give it to get to the following:
{
private List < MDataRow > _Mdr;
public List < MDataRow > Rows
{
get
{
return _Mdr;
}
}
// ...下面省略N行...
}
Then a bit small adjustments, browse again, and finally out the effect of:
At this point, the entire framework of three parts custom MDataTable series, to this end.
Note: The complete source code will be opened in the framework of this series after the end of the chapter released temporarily refrain excitement, learning thinking is important.
If it is found in the learning process have any questions, please leave a message!
Reproduced in: https: //my.oschina.net/secyaher/blog/274068