我有一个DataTable
和DataSet
的问题。我们创建了我们自己的ObservableDataTable
,它可以创建一个ObservableDataRow
。要创建DataTable,我们使用DataSet
。为了创建自定义数据表,我们复制由DataSet
创建的表的模式。但现在我有这个问题,我们的新DataTable
没有DataSet
。这是我们创造的datatabe方式:Derived DataTable has no 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>();
我如何分配的DataSet派生DataTable
?
也许有人曾经这样做过。非常感谢你!
你为什么不能有构造函数接受一个DataSet而不是像'公共ObservableDataTable(数据集DS)'? – Rahul
这也可能是一个想法。我仔细想想。谢谢 – BendEg