BendEg
BendEg

Reputation: 21088

Derived DataTable has no DataSet

I have a problem with DataTable and DataSet. We have created our own ObservableDataTable which can create a ObservableDataRow. To create the DataTable we use a DataSet. For creating the custom datatable we copy the schema of table which is created by the DataSet. But now i have the problem, that our new DataTable has no DataSet. This is the way we create the datatabe:

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);
        }
    }
}

Creating the instance:

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>();

How can i assign the DataSet to the derived DataTable?

Maybe some one has done this before. Thank you very much!

Upvotes: 1

Views: 294

Answers (1)

Canavar
Canavar

Reputation: 48088

Check this, you can add your datatable to a dataset's tables collection, and then your datatable has a dataset :

// 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;

Upvotes: 1

Related Questions