Board index » delphi » Any help gratefull, have almost given up on this!!

Any help gratefull, have almost given up on this!!

Why does this cause a Key Violation and what is a Key Violation???

CustDetails.Insert;
CustDetailsAccountRef.Value := NewAccountRefEdit.Text;
CustDetailsInvoiceAddress.Value := NewInvoiceAddressMemo.Text;
CustDetailsPropertyDetails.Value := NewPropertyDetailsMemo.Text;
CustDetails.Post;

Thanks in advance, I cant see what else could be causing it, the program
does not do anything else with this dataset nor any of the control in the
above code!!

 

Re:Any help gratefull, have almost given up on this!!


Quote
> what is a Key Violation???

A key violation is when the current key (Check the info structure of your
table) already exists in your table.

ie. If AccountRef is you key then you may not have any two records with the
same AccountRef.

Hope the info helped

Thomas Ellis

Re:Any help gratefull, have almost given up on this!!


Quote
"Ian" <i...@igroves.f9.co.uk> wrote in message

news:3944ed1e@news.jakinternet.co.uk...

Quote
> Why does this cause a Key Violation and what is a Key Violation???

> CustDetails.Insert;
> CustDetailsAccountRef.Value := NewAccountRefEdit.Text;
> CustDetailsInvoiceAddress.Value := NewInvoiceAddressMemo.Text;
> CustDetailsPropertyDetails.Value := NewPropertyDetailsMemo.Text;
> CustDetails.Post;

> Thanks in advance, I cant see what else could be causing it, the program
> does not do anything else with this dataset nor any of the control in the
> above code!!

A Key Violation occurs when a table has a "unique" index and you try to post
a record that duplicates an existing key (index entry).

If you are working with a Paradox table I'd guess that AccountRef is the
field that forms the primary index and the code is trying to insert a record
with an AccountRef that is already in the table.

Re:Any help gratefull, have almost given up on this!!


On Mon, 12 Jun 2000 14:58:29 +0100, "Ian" <i...@igroves.f9.co.uk>
wrote:

Quote
>Why does this cause a Key Violation and what is a Key Violation???

>CustDetails.Insert;
>CustDetailsAccountRef.Value := NewAccountRefEdit.Text;
>CustDetailsInvoiceAddress.Value := NewInvoiceAddressMemo.Text;
>CustDetailsPropertyDetails.Value := NewPropertyDetailsMemo.Text;
>CustDetails.Post;

To be sure what is causing this, you should post the database table
details, fields and indeces.
Key violation happens when you post a record with duplicate data in a
field where there should not be duplicates. That is a field used in an
index. A duplicate key is a key violation.
That is my understanding of the matter.
Regards
Johan Smit

Re:Any help gratefull, have almost given up on this!!


On Mon, 12 Jun 2000 14:58:29 +0100, "Ian" <i...@igroves.f9.co.uk>
wrote:

Quote
>Why does this cause a Key Violation and what is a Key Violation???

>CustDetails.Insert;
>CustDetailsAccountRef.Value := NewAccountRefEdit.Text;
>CustDetailsInvoiceAddress.Value := NewInvoiceAddressMemo.Text;
>CustDetailsPropertyDetails.Value := NewPropertyDetailsMemo.Text;
>CustDetails.Post;

To be sure what is causing this, you should post the database table
details, fields and indeces.
Key violation happens when you post a record with duplicate data in a
field where there should not be duplicates. That is a field used in an
index. A duplicate key is a key violation.
That is my understanding of the matter.
Regards
Johan Smit

Re:Any help gratefull, have almost given up on this!!


Quote
Johan Smit wrote:

...
> Key violation happens when you post a record with duplicate data in a
> field where there should not be duplicates. That is a field used in an
> index. A duplicate key is a key violation.

IIRC primary key also implies "not null".  Make sure you aren't trying
to post a record with empty key field.

Dima
--
Smith & Wesson - The original point and click interface...
----------------------------------------------------------
{*word*216}le-{*word*216}le, 23 Confusion 3166, 150:2:4 (1)

Re:Any help gratefull, have almost given up on this!!


On Sun, 18 Jun 2000 14:16:38 -0500, Dima Maziuk

Quote
<dmaz...@crosswinds.net> wrote:
>Johan Smit wrote:

>...
>> Key violation happens when you post a record with duplicate data in a
>> field where there should not be duplicates. That is a field used in an
>> index. A duplicate key is a key violation.

>IIRC primary key also implies "not null".  Make sure you aren't trying
>to post a record with empty key field.

>Dima
>--

Paradox tables can have a null in the key field. [at least for a
single field key]. I see it all the time when I'm debugging and the
key is not being set for some reason-- the first post seems to work,
then the next gives a key violation because the two records have the
same primary key: null.

Dan
--
Dan Brennand
CMDC systems, inc.
Configuration Management and Document Control: Consulting, Software,
and the only comprehesive textbook on this subject.
visit us at www.cmdcsystems.com
[Remove the SPAM from my e-mail address]

Other Threads