none
Wpf remove Constraint from datatable

    Question

  • I have datatable created from MS Access database using DataAdapter.
    for ex: adapter.Fill(result);

    Issue is, MS Access datatable has Primary key. But i dont want to have that
    primary key Constraint to my new datatable.

    I tried below code to remove constraint but it's not working:

    foreach (Constraint cnst in result.Constraints)
       {
          if (result.Constraints.CanRemove(cnst)) // it always returns false.
          {
             result.Constraints.Remove(cnst);
          }
       }

    Error: Cannot remove unique constraint since it's the primary key of table Copy of Table1.

    Please help me how would I delete constraint.

    Thanks
    Dee

    Friday, February 15, 2013 8:08 PM

Answers

All replies

  • Hi,

    you might want to move your thread to the right forum to increase your chance of getting an answer (might be general C# or something about ADO; don't know what's available).

    It definetly has nothing to do with WPF.

    Hope you find some help.

    Jürgen

    Saturday, February 16, 2013 8:46 AM
  • Hi Dee,

    If you want to remove the Primary key from the table, please try this SQL statement:

    DROP INDEX PrimaryKey ON Table1;

    Refer to:

    Create or remove a primary key

    Good day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 28, 2013 6:00 AM
    Moderator
  • Hi Dee,

    I temporarily marked the reply as answer and you can unmark it if it provides no help.
    Please feel free to let us know if you have any concern.

    Thanks for your understanding and have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 06, 2013 10:34 AM
    Moderator