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

12,691

Solution 1

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.

Solution 2

This happens when you have the same column selected in your SQL JOIN Statements. I fixed this problem by removing the the duplicate column from my sql join like this
Change This

    SELECT O.Section,S.CurriculumTblCode, 
    S.Section ,S.SectionSettingTblCode FROM 
    otf.ViewOneToFiveGroups O 
    INNER JOIN 
    SectionSetting S ON O.SectionSettingTblCode= S.SectionSettingTblCode`

To this, Just by removing the duplicate S.Section
     SELECT O.Section,S.CurriculumTblCode,S.SectionSettingTblCode 
     FROM 
     otf.ViewOneToFiveGroups O 
     INNER JOIN SectionSetting S ON O.SectionSettingTblCode= 
     S.SectionSettingTblCode
Share:
12,691
Jacques
Author by

Jacques

Top 5 Reasons Why I Add Value: I understand the concerns of team members, leaders and executives alike, I've been there, made the decisions myself or participated in executive meetings where these decisions were being made. I have worked across most fields in IT and on projects spanning continents, cultures and corporate hierarchies giving me a unique technical and cultural perspective I may not be able to paint the Mona Lisa or compose a beautiful piece of music, I don't even possess a university degree of any kind, but I do have a strong creative streak when it comes to solving problems. I value quality and good customer service I love technology and innovation!

Updated on June 04, 2022

Comments

  • Jacques
    Jacques almost 2 years
    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?

    • Joel Coehoorn
      Joel Coehoorn almost 14 years
      I wonder why they don't just use myDataTableInstance.Load(myDataReaderInstance)
    • Admin
      Admin almost 14 years
      Seems to have solved my problem. Thanks.
  • Arulmouzhi
    Arulmouzhi over 4 years
    it's helpful for me when i use flat file import through SSMS.