DataTable.DefaultView.ToTable() to DataTable

本文关键字:DataTable to ToTable DefaultView | 更新日期: 2023-09-27 18:32:59

为什么这段代码有效。

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

当此代码不...

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

它说"属性或索引器'System.Data.DataTableCollection.this[string]'不能分配给 - 它是只读的"

DataTable.DefaultView.ToTable() to DataTable

错误是不言自明的。因为您尝试将表分配给只读DataSetTables索引器。

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