Home All Groups Group Topic Archive Search About

Q: Deleting a table with constraints

Author
5 Jul 2006 4:25 PM
G .Net
Hi

I have a DataSet with several DataTables. I have set up relations between
these tables.

I want to delete all the tables and re-fill them. However, when I try to do
so, even after using Relations.Clear() I still get excecptions, such as:

Cannot remove ForeignKeyConstraint - remove the constraint first

when trying to remove a table.

Can anybody help???

Author
5 Jul 2006 4:48 PM
Cor Ligthert [MVP]
Lucky enough is it as that is.

You can (normally I have seen a situation that does that) not have children
without a parent.

Therefore you have first to delete all the childs before you can delete the
parent.

If you want to do it than to the database (maybe that is your question),
than you have  to use this.
http://msdn2.microsoft.com/en-us/library/0f8054fy.aspx

First do the deleted children rows
Than the parent rows
Than the modified and added children.

Don't forget to do an acceptchanges on the original dataset.

You see than direct why is that acceptchanges.

I hope this helps,

Cor

Show quoteHide quote
"G .Net" <nodamnspam@email.com> schreef in bericht
news:sP6dnQLGfJh8ejbZRVny2g@pipex.net...
> Hi
>
> I have a DataSet with several DataTables. I have set up relations between
> these tables.
>
> I want to delete all the tables and re-fill them. However, when I try to
> do so, even after using Relations.Clear() I still get excecptions, such
> as:
>
> Cannot remove ForeignKeyConstraint - remove the constraint first
>
> when trying to remove a table.
>
> Can anybody help???
>
>
>
Author
5 Jul 2006 5:06 PM
G .Net
Hi Cor

Thanks for that. I'll have a look.

However, I'm puzzled why clearning the relations doesn't solve it? Surely
that should make the tables seperate (i.e. with no relationships) so I can
simple do something like:

dt.Remove()

for any table. However, as I indicated earlier, this stil throws an
exception.


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uB2GvKFoGHA.4728@TK2MSFTNGP03.phx.gbl...
> Lucky enough is it as that is.
>
> You can (normally I have seen a situation that does that) not have
> children without a parent.
>
> Therefore you have first to delete all the childs before you can delete
> the parent.
>
> If you want to do it than to the database (maybe that is your question),
> than you have  to use this.
> http://msdn2.microsoft.com/en-us/library/0f8054fy.aspx
>
> First do the deleted children rows
> Than the parent rows
> Than the modified and added children.
>
> Don't forget to do an acceptchanges on the original dataset.
>
> You see than direct why is that acceptchanges.
>
> I hope this helps,
>
> Cor
>
> "G .Net" <nodamnspam@email.com> schreef in bericht
> news:sP6dnQLGfJh8ejbZRVny2g@pipex.net...
>> Hi
>>
>> I have a DataSet with several DataTables. I have set up relations between
>> these tables.
>>
>> I want to delete all the tables and re-fill them. However, when I try to
>> do so, even after using Relations.Clear() I still get excecptions, such
>> as:
>>
>> Cannot remove ForeignKeyConstraint - remove the constraint first
>>
>> when trying to remove a table.
>>
>> Can anybody help???
>>
>>
>>
>
>
Author
19 Jul 2006 5:11 PM
Jesse
Did you figure out what the problem was?  I'm running into the same
thing.  I have a dataset with 2 tables in it.  Clearing the relations
doesn't seem to do anything.  Instead I can first clear the child
table, then clear the parent table.  I can't remove the table from the
dataset however.  I get the error 'Cannot remove table ... because it
is referenced in ForeignKeyConstraint ... Remove the constraint first.'

How can I remove the constraint?  Clearing the relations doesn't do it.

Jesse.


G .Net wrote:
Show quoteHide quote
> Hi Cor
>
> Thanks for that. I'll have a look.
>
> However, I'm puzzled why clearning the relations doesn't solve it? Surely
> that should make the tables seperate (i.e. with no relationships) so I can
> simple do something like:
>
> dt.Remove()
>
> for any table. However, as I indicated earlier, this stil throws an
> exception.
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:uB2GvKFoGHA.4728@TK2MSFTNGP03.phx.gbl...
> > Lucky enough is it as that is.
> >
> > You can (normally I have seen a situation that does that) not have
> > children without a parent.
> >
> > Therefore you have first to delete all the childs before you can delete
> > the parent.
> >
> > If you want to do it than to the database (maybe that is your question),
> > than you have  to use this.
> > http://msdn2.microsoft.com/en-us/library/0f8054fy.aspx
> >
> > First do the deleted children rows
> > Than the parent rows
> > Than the modified and added children.
> >
> > Don't forget to do an acceptchanges on the original dataset.
> >
> > You see than direct why is that acceptchanges.
> >
> > I hope this helps,
> >
> > Cor
> >
> > "G .Net" <nodamnspam@email.com> schreef in bericht
> > news:sP6dnQLGfJh8ejbZRVny2g@pipex.net...
> >> Hi
> >>
> >> I have a DataSet with several DataTables. I have set up relations between
> >> these tables.
> >>
> >> I want to delete all the tables and re-fill them. However, when I try to
> >> do so, even after using Relations.Clear() I still get excecptions, such
> >> as:
> >>
> >> Cannot remove ForeignKeyConstraint - remove the constraint first
> >>
> >> when trying to remove a table.
> >>
> >> Can anybody help???
> >>
> >>
> >>
> >
> >
Author
19 Jul 2006 6:09 PM
Jesse
Nevermind, I figured it out.  I had to remove the primary key
constraint AND the foreign key constraint, THEN clear the relations,
THEN I could remove the table.

            ds.Tables("dt1").Constraints.RemoveAt(0)
            ds.Tables("dt2").Constraints.RemoveAt(0)
            ds.Relations.Clear()
            dsOTTR.Tables.Clear()



Jesse wrote:
Show quoteHide quote
> Did you figure out what the problem was?  I'm running into the same
> thing.  I have a dataset with 2 tables in it.  Clearing the relations
> doesn't seem to do anything.  Instead I can first clear the child
> table, then clear the parent table.  I can't remove the table from the
> dataset however.  I get the error 'Cannot remove table ... because it
> is referenced in ForeignKeyConstraint ... Remove the constraint first.'
>
> How can I remove the constraint?  Clearing the relations doesn't do it.
>
> Jesse.
>
>
> G .Net wrote:
> > Hi Cor
> >
> > Thanks for that. I'll have a look.
> >
> > However, I'm puzzled why clearning the relations doesn't solve it? Surely
> > that should make the tables seperate (i.e. with no relationships) so I can
> > simple do something like:
> >
> > dt.Remove()
> >
> > for any table. However, as I indicated earlier, this stil throws an
> > exception.
> >
> >
> > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> > news:uB2GvKFoGHA.4728@TK2MSFTNGP03.phx.gbl...
> > > Lucky enough is it as that is.
> > >
> > > You can (normally I have seen a situation that does that) not have
> > > children without a parent.
> > >
> > > Therefore you have first to delete all the childs before you can delete
> > > the parent.
> > >
> > > If you want to do it than to the database (maybe that is your question),
> > > than you have  to use this.
> > > http://msdn2.microsoft.com/en-us/library/0f8054fy.aspx
> > >
> > > First do the deleted children rows
> > > Than the parent rows
> > > Than the modified and added children.
> > >
> > > Don't forget to do an acceptchanges on the original dataset.
> > >
> > > You see than direct why is that acceptchanges.
> > >
> > > I hope this helps,
> > >
> > > Cor
> > >
> > > "G .Net" <nodamnspam@email.com> schreef in bericht
> > > news:sP6dnQLGfJh8ejbZRVny2g@pipex.net...
> > >> Hi
> > >>
> > >> I have a DataSet with several DataTables. I have set up relations between
> > >> these tables.
> > >>
> > >> I want to delete all the tables and re-fill them. However, when I try to
> > >> do so, even after using Relations.Clear() I still get excecptions, such
> > >> as:
> > >>
> > >> Cannot remove ForeignKeyConstraint - remove the constraint first
> > >>
> > >> when trying to remove a table.
> > >>
> > >> Can anybody help???
> > >>
> > >>
> > >>
> > >
> > >