如何创建一个类型化的DataTable

时间:2013-10-28 13:20:52

标签: c# datatable

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

我做了:

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内部引用它自己的类呢?

由于

1 个答案:

答案 0 :(得分:0)

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

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

从概念上讲,我强烈反对这个问题,DataTable元素和DataTableFiller元素(由您的LoadData方法表示)应该在两个不同的类中解耦。