Search code examples
.nett-sqldatatabledotnetnuke

A column named [column name] already belongs to this DataTable


private void BindFields()
{
    DataTable table = Globals.ConvertDataReaderToDataTable(DataProvider.GetFields());
    _fieldCount = table.Rows.Count;

    dataGrid.DataSource = table;
    dataGrid.DataBind();
}

The ConvertDataReaderToDataTable, provided by the DotNetNuke platform, throws this exception :

A column named [column name] already belongs to this DataTable

I do have columns with the same names in different tables, but they are primary/foreign key pairs and thus have the same values. What would you do to solve this problem?


Solution

  • I simply used

    DataTable dataTable = new DataTable();
    dataTable.Load(dataReader);
    

    instead of DotNetNuke's

    DataTable dataTable = Globals.ConvertDataReaderToDataTable(dataReader);
    

    and I don't get the exception anymore.