2
Answers

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

Murali krishna  Ande

Murali krishna Ande

13y
4.7k
1
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.


Answers (2)