views:

157

answers:

2
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?

A: 

You would typically only use one of the columns in the data source. Short of that, you would alias one of the other columns.

Using only one of the duplicates

Select a.SomeColumn, b.OtherStuff
From TableA a
Inner Join TableB b
on a.SomeColumn = b.SomeColumn

Or using an alias

Select a.SomeColumn, b.SomeColumn as SomeColumnB, b.OtherStuff
From TableA a
Inner Join TableB b
on a.SomeColumn = b.SomeColumn
Anthony Pegram
A: 

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.

asmo