Board index » delphi » Identity field error

Identity field error


2004-11-21 12:49:11 AM
delphi174
I am using Delphi 7 and BDE to update/add records to a MS SQL 2000 table.
This table has an identity field.
My code is as follows:
procedure TForm1.Button2Click(Sender: TObject);
begin
With Table1 do begin
Open;
Append;
FieldbyName('TransNumbe').asInteger := 123;
FieldbyName('AccountInd').asInteger := 456;
FieldbyName('SubNumber').AsInteger := 1;
FieldbyName('TransDate').AsDateTime := Date() + Time() ;
FieldbyName('Operator').AsString := 'JWC';
//FieldbyName('eUnique').AsFloat := 1;
post;
end;
end;
If I execute this, I get an error "field eUnique must have a value. eUnique
is my Identity field.
If I uncomment the eUnique, I get an error "cannot insert explicit value for
identity column when
IDENTITY_INSERT is set to off.
How can I get around this?
Jim
 
 

Re:Identity field error

Using the BDE is not a good idea as it is no longer being developed or
maintained. ADO is a much better choice for SQL Server. Using TTable or
any other table component with a SQL database server will cause poor
performance and is not scalable. Use a query component instead and use
SELECT statements with WHERE clauses that return a small number of rows.
To solve your immediate problem set the Required property of the field
object for your identity field to false.
--
Bill (TeamB)
TeamB cannot answer questions received via email
 

Re:Identity field error

groups.google.com/groups&lr=&num=50&hl=nl
Jan
"Jim" <XXXX@XXXXX.COM>schreef in bericht
Quote
I am using Delphi 7 and BDE to update/add records to a MS SQL 2000 table.
This table has an identity field.
My code is as follows:

procedure TForm1.Button2Click(Sender: TObject);
begin
With Table1 do begin
Open;
Append;
FieldbyName('TransNumbe').asInteger := 123;
FieldbyName('AccountInd').asInteger := 456;
FieldbyName('SubNumber').AsInteger := 1;
FieldbyName('TransDate').AsDateTime := Date() + Time() ;
FieldbyName('Operator').AsString := 'JWC';
//FieldbyName('eUnique').AsFloat := 1;
post;
end;
end;

If I execute this, I get an error "field eUnique must have a value.
eUnique
is my Identity field.

If I uncomment the eUnique, I get an error "cannot insert explicit value
for
identity column when
IDENTITY_INSERT is set to off.

How can I get around this?

Jim


 

Re:Identity field error

IF the field is an autonumber identity filed, you should not insert a value
to it.
Regards,
Lucian Rosu
"Jim" <XXXX@XXXXX.COM>writes
Quote
I am using Delphi 7 and BDE to update/add records to a MS SQL 2000 table.
This table has an identity field.
My code is as follows:

procedure TForm1.Button2Click(Sender: TObject);
begin
With Table1 do begin
Open;
Append;
FieldbyName('TransNumbe').asInteger := 123;
FieldbyName('AccountInd').asInteger := 456;
FieldbyName('SubNumber').AsInteger := 1;
FieldbyName('TransDate').AsDateTime := Date() + Time() ;
FieldbyName('Operator').AsString := 'JWC';
//FieldbyName('eUnique').AsFloat := 1;
post;
end;
end;

If I execute this, I get an error "field eUnique must have a value.
eUnique
is my Identity field.

If I uncomment the eUnique, I get an error "cannot insert explicit value
for
identity column when
IDENTITY_INSERT is set to off.

How can I get around this?

Jim


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.804 / Virus Database: 546 - Release Date: 30/11/2004