Skip to content

Got the error "Cannot have more than 32 columns" while creating datarelation b/w datacolumns.....?????

Murali krishna Ande

Asked Jun 7, 2011, 9:56 PM EDT2 answers
Share
LinkedInX
Hi,

I am comparing to datatables and returning differences with another datatable...

But I got the error while creating the data relation i.e., "Cannot have more than 32 Columns" which is in red color.

private DataTable GetDifferences(DataTable dbTable, DataTable xlTable)
        {

            DataTable resultTable = new DataTable();

            using (DataSet ds = new DataSet())
            {
                ds.Tables.AddRange(new DataTable[] { dbTable.Copy(), xlTable.Copy() });

                DataColumn[] dbTableColumns = new DataColumn[ds.Tables[0].Columns.Count];
                for (int i = 0; i < dbTableColumns.Length; i++)
                {
                    dbTableColumns[i] = ds.Tables[0].Columns[i];
                }

                DataColumn[] xlTableColumns = new DataColumn[ds.Tables[1].Columns.Count];
                for (int i = 0; i < xlTableColumns.Length; i++)
                {
                    xlTableColumns[i] = ds.Tables[1].Columns[i];
                }

                DataRelation dr1 = new DataRelation(string.Empty, dbTableColumns, xlTableColumns, false);
                ds.Relations.Add(dr1);

                DataRelation dr2 = new DataRelation(string.Empty, xlTableColumns, dbTableColumns, false);
                ds.Relations.Add(dr2);

                for (int i = 0; i < dbTable.Columns.Count; i++)
                {
                    resultTable.Columns.Add(dbTable.Columns[i].ColumnName, dbTable.Columns[i].DataType);
                }

                resultTable.BeginLoadData();
                foreach (DataRow parentRow in ds.Tables[0].Rows)
                {
                    DataRow[] childRows = parentRow.GetChildRows(dr1);
                    if (childRows == null || childRows.Length == 0)
                        resultTable.LoadDataRow(parentRow.ItemArray, true);
                }

                foreach (DataRow parentRow in ds.Tables[1].Rows)
                {
                    DataRow[] childRows = parentRow.GetChildRows(dr2);
                    if (childRows == null || childRows.Length == 0)
                        resultTable.LoadDataRow(parentRow.ItemArray, true);
                }
                resultTable.EndLoadData();
            }
            return resultTable;
        }


can some body plz tell me how can we sort out this issue..??

Thanks
Murali krishna.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Why you're trying to create a relationship here?
    0
  • 0
    //This assumes the datatables have the same structure....

    public bool CompareDataTable(DataTable t1, DataTable t2) {                      
                   
    if (t1.Rows.Count != t2.Rows.Count) 
                           
    return false; 
     
                   
    foreach (DataColumn dc in t1.Columns) { 
                           
    for (int i = 0; i < t1.Rows.Count; i++) { 
                                   
    if (t1.Rows[i][dc.ColumnName] != t2.Rows[i][dc.ColumnName]) { 
                                           
    return false; 
                                   
    } 
                           
    } 
                   
    } 
                   
    return true; 
           
    } 

    http://forums.asp.net/p/991360/1288387.aspx
    http://forums.asp.net/t/1288629.aspx
    http://forums.asp.net/t/1626255.aspx
    http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/63a082d2-ddd8-420e-8976-9ad4a5fca022

    Hope this helps you.
    0