CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    145

    Filling a DataTable by importing some rows from 2 other DataTables

    I’m filling a DataTable ‘C’ by importing some rows from 2 other DataTables ‘A’ and ‘B’ with the same structure.
    The problem is that there is a unique column ‘id’ defined in the table, so it happens that I am trying to import 2 rows with the same ‘id’ value, and of-course I get a
    System.Data.ConstraintException saying "Column 'id' is constrained to be unique. Value '0' is already present."

    Is there a way to avoid this?
    I can create a new row in table ‘C’ and copy each column’s value from the other table’s row, except the value of the unique column, but I wanted to use ImportRow to avoid this.

  2. #2
    Join Date
    Mar 2007
    Posts
    274

    Re: Filling a DataTable by importing some rows from 2 other DataTables

    Assign new unique id's to the columns in question, before importing them. Otherwise I think your only option is to add the rows manually to your table.

  3. #3
    Join Date
    Apr 2006
    Posts
    220

    Re: Filling a DataTable by importing some rows from 2 other DataTables

    Quote Originally Posted by Traps View Post
    Assign new unique id's to the columns in question, before importing them. Otherwise I think your only option is to add the rows manually to your table.
    Agreed.

  4. #4
    Join Date
    Mar 2003
    Posts
    145

    Re: Filling a DataTable by importing some rows from 2 other DataTables

    Quote Originally Posted by Traps View Post
    Assign new unique id's to the columns in question, before importing them. Otherwise I think your only option is to add the rows manually to your table.
    I don't want to change the original tables, because they are connected to other tables. So, I guess I'll have to add new rows manually like you suuggested.
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured