1
votes

The Crystal Report was developed and worked fine in version 10.5 and under Visual Studio 2008 (.NET framework 3.5). However, when migrated to Version 13.0.2 and Visual Studio 2010 (.NET framework 4.0). I got the error below:

Anyone had the similar experience? Any help or solution would be welcome.


Message: A column named '**Item**' already belongs to this DataTable.
Source: System.Data
Current Method: Void RegisterColumnName(System.String, System.Data.DataColumn)
Stack Trace:
    at System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column)
    at System.Data.DataColumnCollection.BaseAdd(DataColumn column)
    at System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn column)
    at System.Data.DataColumnCollection.Add(String columnName, Type type)
    at CrystalDecisions.CrystalReports.Engine.Table.BuildTableFromMemberInfos(ArrayList memberInfos, Boolean autoFlattenCurrentLevel, Int32 currentLevel, Int32 maximumLevels, String namePrefix, DataTable table)
    at CrystalDecisions.CrystalReports.Engine.Table.BuildTableFromEnumerable(IEnumerable collection, Type dataClassType, String tableName)
    at CrystalDecisions.CrystalReports.Engine.Table.EnumerableToDataSet(IEnumerable collection)
    at CrystalDecisions.CrystalReports.Engine.Table.WrapAndCacheDotNetObject(Object val, Type type, ISCRAdoNetDataSet& crAdoNetDataSet)
    at CrystalDecisions.CrystalReports.Engine.Table.SetDataSource(Object val, Type type)
    at CrystalDecisions.CrystalReports.Engine.Table.SetDataSource(IEnumerable enumerable)*

Added the source code, DetailSps and other dataset are defined in a .xsd file. The error is from: Report.Database.Tables["DetailSps"].SetDataSource:

    public void CreateReport(ReportInfo reportInfo)
    {
        PopulateReportData(reportInfo.SpecDetail.Table);

        ReportClass Report = new DetailsRpt();

        Report.ReportOptions.EnableSaveDataWithReport = true;
        Report.ReportOptions.EnableSaveSummariesWithReport = true;

        // now add the tables used in Report
        Report.Database.Tables["DetailSps"].SetDataSource(
            DetailSps.OrderBy(x => x.ID)
                .ThenBy(x => x.Specall_ID));


    .....
}


    private void PopulateReportData(DataTable dt)
    {
        foreach (DataRow dr in dt.Rows)
        {
            DetailSps.AddDetailsRow(
                (String)dr["ID"], 
                (String)dr["Type"], 
                CommonDateFunctions.FormatStringAsDateMDYYYY(dr["selected_date"].ToString()), 
        ......
                (String)dr["ErrorCode"]
                );
        }

        ....
    }
2
Can I suggest posting the relevant code as well?Derek Tomes
This issue has been resolved. Thanks nunzabar and Derek. It is caused by the 'Item' object added by Crystal Report in VS 2010, and LINQ is complaining about it when it sets the DataSource.Ming Lu
@MingLu I have the same error, can you post how you resolved it, I cant see any 'item' column added to my dataset?Sharkz

2 Answers

1
votes

I recall having the exact same problem a year ago when upgrading a project. I determined that the "Item" conflict was caused by a Visual Studio designer creating an Item object in one of its auto-generated code files. In my case, I think it was the XML Schema designer I was using to model the Crystal data source.

I ended up renaming my column to not be "Item".

0
votes

For debugging purposes, I'd try breaking up this line:

    // now add the tables used in Report
    Report.Database.Tables["DetailSps"].SetDataSource(
        DetailSps.OrderBy(x => x.ID).ThenBy(x => x.Specall_ID));

To something like:

    DataTable dataTable = DetailSps.OrderBy(x => x.ID).ThenBy(x => x.Specall_ID);

    Report.Database.Tables["DetailSps"].SetDataSource(dataTable);

To see if you can isolate the problem a little further.

Maybe also put a break point just before the offending line and have a look at the data table in your quick watch window or iterate through all the columns / rows and look at the names and data...