Following on a realization MDataTable, we'll add to MDataTable a NewRow () method, in order to construct a new row of the table
as follows:
public MDataRow NewRow()
{
MDataRow mdr = new MDataRow();
mdr.TableName = _TableName;
MDataCellStruct mdcStruct = null;
for (int i = 0; i < this.Columns.Count; i++)
{
mdcStruct=this.Columns[i];
mdr.Add(new MDataCell(ref mdcStruct));
}
return mdr;
}
OK, Next, we create a new web project Demo, in Default.aspx casually drag a GridView control into it, and then write the following code in the Page_Load in:
MDataTable table=new MDataTable("myTableName");
table.Columns.Add("A", SqlDbType.NVarChar);
table.Columns.Add("B",SqlDbType.NVarChar);
MDataRow mdr = table.NewRow();
mdr[0].Value = "helloA";
mdr[1].Value = "111111";
table.Add(mdr);
GridView1.DataSource = table;
GridView1.DataBind();
Knock mdr [ "A"] this was supposed to knock, do not support the string cable, had knocked mdr [0], and where the way of adding a character string MDataRow index, as follows:
public MDataCell this[string Key]
{
get
{
MDataCell dataCell = null;
for (int i = 0; i < base.Count; i++)
{
if (base[i].ColumnName == Key)
{
dataCell = base[i];
break;
}
}
return dataCell;
}
}
The OK, so adds two columns head, and a row of data is added after the operation to see the results as follows:
TableName | ConnectionString | Capacity | Count |
---|---|---|---|
myTableName | 4 | 2 |
Halo, the data is not what we want ....
Column shown above, there are three attributes of Table, there is a ConnectionString attribute row Table
Scare, loud noise mixed in a few weeks. . . .
So, we started working to find the binding law ...
Reproduced in: https: //my.oschina.net/secyaher/blog/274079