我有一個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