469,609 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Q: Deleting a table with constraints

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???

Jul 5 '06 #1
4 3263
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" <no********@email.comschreef in bericht
news:sP********************@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???

Jul 5 '06 #2
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]" <no************@planet.nlwrote in message
news:uB**************@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" <no********@email.comschreef in bericht
news:sP********************@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???


Jul 5 '06 #3
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]" <no************@planet.nlwrote in message
news:uB**************@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" <no********@email.comschreef in bericht
news:sP********************@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???
Jul 19 '06 #4
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:
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]" <no************@planet.nlwrote in message
news:uB**************@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" <no********@email.comschreef in bericht
news:sP********************@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???
>>
>>
>>
>
>
Jul 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

36 posts views Thread by toedipper | last post: by
17 posts views Thread by Dr NoName | last post: by
4 posts views Thread by maricel | last post: by
5 posts views Thread by G .Net | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.