CYQ.Data lightweight data access layer (vii) implement a custom data tables commonly used data binding controls (on)

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:

05233228_uiRq.gif 05233229_2kFG.gif Code
 public MDataRow NewRow()
05233229_2kFG.gif05233228_uiRq.gif        
{
            MDataRow mdr 
= new MDataRow();
            mdr.TableName 
= _TableName;
            MDataCellStruct mdcStruct 
= null;
            
for (int i = 0; i < this.Columns.Count; i++)
05233229_3aCP.gif05233229_fZFo.gif            
{
                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:

05233228_uiRq.gif 05233229_2kFG.gif Code
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:

05233228_uiRq.gif 05233229_2kFG.gif Code
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

Guess you like

Origin blog.csdn.net/weixin_34218890/article/details/91966701