Q: deleting relations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • G .Net

    #1

    Q: deleting relations

    Hi

    I'm hoping that somebody can help me with a fairly puzzling problem.

    I've created some DataTables which have relations between them e.g. one to
    many. In the application, I want to remove entries from the table. To do
    this I obviously need to temporarily switch off the relations. In order to
    achieve this, I tried:

    ds.Relations.Cl ear() ' where ds is the application DataSet
    ds.Tables("tabl e1").Clear()

    but I get the exception:

    "An unhandled exception of type 'System.Argumen tException' occurred in
    system.data.dll
    Additional information: Cannot remove unique constraint 'Constraint1'.
    Remove foreign key constraint table1_table3' first."

    What I don't understand is why the relations don't seem to have been
    removed.

    Can anybody point me in the right direction i.e. how do I switch off the
    relations to allow the clearing of a table?

    Many thanks in advance

    Geoff


  • tomb

    #2
    Re: Q: deleting relations

    The exception is telling you to remove your indexes first - there is a
    foreign key index from the child table to the parent. Remove that
    first, then remove the relation.

    T

    G .Net wrote:
    >Hi
    >
    >I'm hoping that somebody can help me with a fairly puzzling problem.
    >
    >I've created some DataTables which have relations between them e.g. one to
    >many. In the application, I want to remove entries from the table. To do
    >this I obviously need to temporarily switch off the relations. In order to
    >achieve this, I tried:
    >
    >ds.Relations.C lear() ' where ds is the application DataSet
    >ds.Tables("tab le1").Clear()
    >
    >but I get the exception:
    >
    >"An unhandled exception of type 'System.Argumen tException' occurred in
    >system.data.dl l
    >Additional information: Cannot remove unique constraint 'Constraint1'.
    >Remove foreign key constraint table1_table3' first."
    >
    >What I don't understand is why the relations don't seem to have been
    >removed.
    >
    >Can anybody point me in the right direction i.e. how do I switch off the
    >relations to allow the clearing of a table?
    >
    >Many thanks in advance
    >
    >Geoff
    >
    >
    >
    >

    Comment

    • GhostInAK

      #3
      Re: Q: deleting relations

      Hello G .Net,

      Goofball. The relationships are there for a reason. They define how you
      are to interact with the data. Follow their rules.

      -Boo
      Hi
      >
      I'm hoping that somebody can help me with a fairly puzzling problem.
      >
      I've created some DataTables which have relations between them e.g.
      one to many. In the application, I want to remove entries from the
      table. To do this I obviously need to temporarily switch off the
      relations. In order to achieve this, I tried:
      >
      ds.Relations.Cl ear() ' where ds is the application DataSet
      ds.Tables("tabl e1").Clear()
      >
      but I get the exception:
      >
      "An unhandled exception of type 'System.Argumen tException' occurred in
      system.data.dll
      Additional information: Cannot remove unique constraint 'Constraint1'.
      Remove foreign key constraint table1_table3' first."
      What I don't understand is why the relations don't seem to have been
      removed.
      >
      Can anybody point me in the right direction i.e. how do I switch off
      the relations to allow the clearing of a table?
      >
      Many thanks in advance
      >
      Geoff
      >

      Comment

      • G .Net

        #4
        Re: Q: deleting relations

        Err, yes I know they're there for a reason ;) but I have my reasons for
        doing this!

        Geoff

        "GhostInAK" <ghostinak@gmai l.comwrote in message
        news:c71747b42d 9b38c895c147479 9fa@news.micros oft.com...
        Hello G .Net,
        >
        Goofball. The relationships are there for a reason. They define how you
        are to interact with the data. Follow their rules.
        >
        -Boo
        >
        >Hi
        >>
        >I'm hoping that somebody can help me with a fairly puzzling problem.
        >>
        >I've created some DataTables which have relations between them e.g.
        >one to many. In the application, I want to remove entries from the
        >table. To do this I obviously need to temporarily switch off the
        >relations. In order to achieve this, I tried:
        >>
        >ds.Relations.C lear() ' where ds is the application DataSet
        >ds.Tables("tab le1").Clear()
        >>
        >but I get the exception:
        >>
        >"An unhandled exception of type 'System.Argumen tException' occurred in
        >system.data.dl l
        >Additional information: Cannot remove unique constraint 'Constraint1'.
        >Remove foreign key constraint table1_table3' first."
        >What I don't understand is why the relations don't seem to have been
        >removed.
        >>
        >Can anybody point me in the right direction i.e. how do I switch off
        >the relations to allow the clearing of a table?
        >>
        >Many thanks in advance
        >>
        >Geoff
        >>
        >
        >

        Comment

        • G .Net

          #5
          Re: Q: deleting relations

          Hi T

          Could you tell me how to remove the indexes?

          Geoff

          "tomb" <tomb@technetce nter.comwrote in message
          news:oOrHg.1596 6$e9.2430@bigne ws4.bellsouth.n et...
          The exception is telling you to remove your indexes first - there is a
          foreign key index from the child table to the parent. Remove that first,
          then remove the relation.
          >
          T
          >
          G .Net wrote:
          >
          >>Hi
          >>
          >>I'm hoping that somebody can help me with a fairly puzzling problem.
          >>
          >>I've created some DataTables which have relations between them e.g. one to
          >>many. In the application, I want to remove entries from the table. To do
          >>this I obviously need to temporarily switch off the relations. In order to
          >>achieve this, I tried:
          >>
          >>ds.Relations. Clear() ' where ds is the application DataSet
          >>ds.Tables("ta ble1").Clear()
          >>
          >>but I get the exception:
          >>
          >>"An unhandled exception of type 'System.Argumen tException' occurred in
          >>system.data.d ll
          >>Additional information: Cannot remove unique constraint 'Constraint1'.
          >>Remove foreign key constraint table1_table3' first."
          >>
          >>What I don't understand is why the relations don't seem to have been
          >>removed.
          >>
          >>Can anybody point me in the right direction i.e. how do I switch off the
          >>relations to allow the clearing of a table?
          >>
          >>Many thanks in advance
          >>
          >>Geoff
          >>
          >>

          Comment

          • G .Net

            #6
            Re: Q: deleting relations

            Basically, I need to know how to remove Unique and ForeignKey constraints.
            The following line of code does not work:
            ds.Tables("Tabl e1").Constraint s.Clear()

            Thanks in advance

            Geoff

            "G .Net" <nodamnspam@ema il.comwrote in message
            news:hp6dnf3JQI eyInPZnZ2dnUVZ8 s2dnZ2d@pipex.n et...
            Hi T
            >
            Could you tell me how to remove the indexes?
            >
            Geoff
            >
            "tomb" <tomb@technetce nter.comwrote in message
            news:oOrHg.1596 6$e9.2430@bigne ws4.bellsouth.n et...
            >The exception is telling you to remove your indexes first - there is a
            >foreign key index from the child table to the parent. Remove that first,
            >then remove the relation.
            >>
            >T
            >>
            >G .Net wrote:
            >>
            >>>Hi
            >>>
            >>>I'm hoping that somebody can help me with a fairly puzzling problem.
            >>>
            >>>I've created some DataTables which have relations between them e.g. one
            >>>to many. In the application, I want to remove entries from the table. To
            >>>do this I obviously need to temporarily switch off the relations. In
            >>>order to achieve this, I tried:
            >>>
            >>>ds.Relations .Clear() ' where ds is the application DataSet
            >>>ds.Tables("t able1").Clear()
            >>>
            >>>but I get the exception:
            >>>
            >>>"An unhandled exception of type 'System.Argumen tException' occurred in
            >>>system.data. dll
            >>>Additional information: Cannot remove unique constraint 'Constraint1'.
            >>>Remove foreign key constraint table1_table3' first."
            >>>
            >>>What I don't understand is why the relations don't seem to have been
            >>>removed.
            >>>
            >>>Can anybody point me in the right direction i.e. how do I switch off the
            >>>relations to allow the clearing of a table?
            >>>
            >>>Many thanks in advance
            >>>
            >>>Geoff
            >>>
            >>>
            >
            >

            Comment

            Working...