473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3439
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, plane, tractor etc etc For the table design I am...
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 this will be growing by 100 million every week. At a...
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 each other. A 3rd table C, inherits from A. A...
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 narrowed it down to one SQL statement + some...
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 "ADMINISTRATOR"."T1" ADD PRIMARY KEY
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 to many. In the application, I want to remove...
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 other. I use: INSERT INTO table ( column,...
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 to look for to see if it has been posted here...
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 number of different columns. I've noticed a ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.