472,348 Members | 1,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

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 3374
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike,...
4
by: harish | last post by:
DELETING 100 million from a table weekly SQl SERVER 2000 Hi All We have a table in SQL SERVER 2000 which has about 250 million records and...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to...
17
by: Dr NoName | last post by:
Help! I have a table that multiple processes must be able to write to concurrently. However, it for some reason gets locked in exclusive mode. I...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE...
5
by: G .Net | last post by:
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...
8
by: markjerz | last post by:
Hi, I basically have two tables with the same structure. One is an archive of the other (backup). I want to essentially insert the data in to the...
3
by: JHNielson | last post by:
I am not new to Access, but am new to the level of complexity I am now having to get into, so this question may be easy, but I don't even know what...
5
by: yeoj13 | last post by:
Hello, I have a db2load script I'm using to populate a large table. Ideally, my target table is required to have "Not Null" constraints on a...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.