2013-10-28 82 views
0

我创建了一个派生自DataTable的类,我想调用一个负责创建我的自定义DT的方法。如何创建一个类型的DataTable

我所做的:

public class MyDataTable : DataTable 
{ 
    public MyDataTable(){ 
    } 

    public void LoadData(){ 
    //I want to create here the procedure to fill my DT 
    //I want to do something like this = new DataTable in order to reference this class later. I know that this is readonly but I think you get the idea 
    } 

} 

然后我想打电话给我的新类这样

MyDataTable dt = new MyDataTable(); 
dt.LoadData(); 

而且我要的是DT包含了所有的信息。那么我怎么能在我的LoadData中引用类内部的类呢?

谢谢

+3

你的意思是“这个”? – Ralf

+0

@Ralf恐怕他有。 – Tafari

回答

0

为什么你不访问基类的属性和方法?

public void LoadData(){ 
    Rows.Add(...); 
} 

概念,我强烈反对这项建议计算策略,一个DataTable元素和DataTableFiller元素(由LoadData法为代表)应在两个不同的类中分离。

+0

谢谢!用这个简单的线条,你给出了所有的想法。 DataRow dr = this.NewRow(); ...... Rows.Add(dr); –