James Leitz
James Leitz

Reputation: 75

DataTable.DefaultView.ToTable() to DataTable

Why does this code work..

DataTable dt = new DataTable();
            dt = sitesformdataset.Tables[MainTableStringName].DefaultView.ToTable();

When this code does not...

sitesformdataset.Tables[MainTableStringName] = sitesformdataset.Tables[MainTableStringName].DefaultView.ToTable();

It says "Property or indexer 'System.Data.DataTableCollection.this[string]' cannot be assigned to -- it is read only"

Upvotes: 0

Views: 4307

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460068

The error is self-explanatory. Because you try to assign a table to the Tables indexer of the DataSet which is readonly.

public DataTable this[
    string name
] { get; }  // <-- readonly

Upvotes: 2

Related Questions