// check tha column from 2 tables that has the same name also has the same datatype.
 private static void checkColumnTypes(DataTable targetTable, DataTable sourceTable)
 {
     for (int i = 0; i < sourceTable.Columns.Count; i++)
     {
         DataColumn fromCol = sourceTable.Columns[i];
         DataColumn toCol   = targetTable.Columns[fromCol.ColumnName];
         if (toCol == null)
         {
             continue;
         }
         if (toCol.DataTypeMatches(fromCol))
         {
             continue;
         }
         throw new DataException("<target>." + fromCol.ColumnName + " and <source>." +
                                 fromCol.ColumnName + " have conflicting properties: DataType " +
                                 " property mismatch.");
     }
 }
        private void _validateColumns(DataColumn[] parentColumns, DataColumn[] childColumns)
        {
            //not null
            if (null == parentColumns || null == childColumns)
            {
                throw new ArgumentNullException();
            }

            //at least one element in each array
            if (parentColumns.Length < 1 || childColumns.Length < 1)
            {
                throw new ArgumentException("Neither ParentColumns or ChildColumns can't be" +
                                            " zero length.");
            }

            //same size arrays
            if (parentColumns.Length != childColumns.Length)
            {
                throw new ArgumentException("Parent columns and child columns must be the same length.");
            }


            DataTable ptable = parentColumns[0].Table;
            DataTable ctable = childColumns[0].Table;

            for (int i = 0; i < parentColumns.Length; i++)
            {
                DataColumn pc = parentColumns[i];
                DataColumn cc = childColumns[i];

                //not null check
                if (null == pc.Table)
                {
                    throw new ArgumentException("All columns must belong to a table." +
                                                " ColumnName: " + pc.ColumnName + " does not belong to a table.");
                }

                //All columns must belong to the same table
                if (ptable != pc.Table)
                {
                    throw new InvalidConstraintException("Parent columns must all belong to the same table.");
                }

                //not null check
                if (null == cc.Table)
                {
                    throw new ArgumentException("All columns must belong to a table." +
                                                " ColumnName: " + pc.ColumnName + " does not belong to a table.");
                }

                //All columns must belong to the same table.
                if (ctable != cc.Table)
                {
                    throw new InvalidConstraintException("Child columns must all belong to the same table.");
                }

                if (pc.CompiledExpression != null)
                {
                    throw new ArgumentException(String.Format("Cannot create a constraint based on Expression column {0}.", pc.ColumnName));
                }

                if (cc.CompiledExpression != null)
                {
                    throw new ArgumentException(String.Format("Cannot create a constraint based on Expression column {0}.", cc.ColumnName));
                }
            }

            //Same dataset.  If both are null it's ok
            if (ptable.DataSet != ctable.DataSet)
            {
                //LAMESPEC: spec says InvalidConstraintExceptoin
                //	impl does InvalidOperationException
                throw new InvalidOperationException("Parent column and child column must belong to" +
                                                    " tables that belong to the same DataSet.");
            }


            int identicalCols = 0;

            for (int i = 0; i < parentColumns.Length; i++)
            {
                DataColumn pc = parentColumns[i];
                DataColumn cc = childColumns[i];

                if (pc == cc)
                {
                    identicalCols++;
                    continue;
                }

                if (!pc.DataTypeMatches(cc))
                {
                    //LAMESPEC: spec says throw InvalidConstraintException
                    //		implementation throws InvalidOperationException
                    throw new InvalidOperationException("Parent column is not type compatible with it's child"
                                                        + " column.");
                }
            }
            if (identicalCols == parentColumns.Length)
            {
                throw new InvalidOperationException("Property not accessible because 'ParentKey and ChildKey are identical.'.");
            }
        }