派生的DataTable没有DataSet

时间:2015-09-22 12:17:30

标签: c# datatable dataset datarow

我对DataSetObservableDataTable有疑问。我们创建了自己的ObservableDataRow,可以创建DataSet。要创建DataTable,我们使用DataSet。为了创建自定义数据表,我们复制由DataTable创建的表的模式。但现在我遇到了问题,我们的新DataSet没有public class ObservableDataTable : DataTable { /// <summary> /// Initializes a new instance of the System.Data.DataTable class with no arguments. /// </summary> public ObservableDataTable() : base() { } /// <summary> /// Create datatable from existing table and copy schema /// </summary> /// <param name="table">Table which contains a schema to copy</param> public ObservableDataTable(DataTable table) : base() { using (MemoryStream stream = new MemoryStream()) { // Get xml schema for copy purpose table.WriteXmlSchema(stream); stream.Position = 0; this.ReadXmlSchema(stream); } } } 。这是我们创建数据的方式:

DbDataAdapter adapter = GetAdapter();
endOfResult = false;
command.Connection = connection;
countCommand.Connection = connection;
adapter.SelectCommand = command;
currentDataSet = new DataSet();
adapter.FillSchema(currentDataSet, SchemaType.Source, "ResultTable");

resultTable = new ObservableDataTable(currentDataSet.Tables["ResultTable"]);

observableCollection = new RadObservableCollection<ObservableDataRow>();

创建实例:

DataTable

如何将DataSet分配给派生的{{1}}?

也许有人曾经这样做过。非常感谢你!

1 个答案:

答案 0 :(得分:1)

选中此项,您可以将数据表添加到数据集的表集合中,然后数据表中包含数据集:

// Your code here
resultTable = new ObservableDataTable(currentDataSet.Tables["ResultTable"]);
DataSet ds = new DataSet();
ds.Tables.Add(resultTable);
// Now your datatable have dataset : 
int tableCount = resultTable.DataSet.Tables.Count;