Board index » cppbuilder » Field cannot be modified error

Field cannot be modified error


2006-03-02 04:16:21 PM
cppbuilder94
Hi,
I am now using C++ builder 2006 and MS acccess 2003.
I have simple table Table1 in Access with the following fields. This table
is linked to other table.
1) id autonumber
2) Name String
I have to add nearly 10000 rows to the table.
I have to also insert into the 'id' field.
I am using TADOQuery to insert.
If I use,
INSERT INTO Table1(id,Name) VALUES(2,"sms")
ExecSQL()
there is no problem.
If I use,
ADOQuery1->Insert();
ADOQuery1->FieldValues["id"]=2 ;
ADOQuery1->FieldValues["Name"]="sms";
ADOQuery1->Post();
I get the error "Field 'id' cannot be modified".
Why?
Insert into the dataset is faster compared to using ExecSQL() 10000 times.
Please help.
Regards,
Siraj
 
 

Re:Field cannot be modified error

"siraj" < XXXX@XXXXX.COM >ha scritto nel messaggio
Quote
Hi,
I am now using C++ builder 2006 and MS acccess 2003.
I have simple table Table1 in Access with the following fields. This table
is linked to other table.
1) id autonumber
2) Name String

I have to add nearly 10000 rows to the table.
I have to also insert into the 'id' field.

I am using TADOQuery to insert.
If I use,
INSERT INTO Table1(id,Name) VALUES(2,"sms")
ExecSQL()
there is no problem.

If I use,
ADOQuery1->Insert();
ADOQuery1->FieldValues["id"]=2 ;
ADOQuery1->FieldValues["Name"]="sms";
ADOQuery1->Post();
I get the error "Field 'id' cannot be modified".

Why?

Insert into the dataset is faster compared to using ExecSQL() 10000 times.

Please help.

Regards,
Siraj

You must use:
ADOQuery1->Insert();
ADOQuery1->FieldByName("id")->AsInteger = 2 ;
ADOQuery1->FieldByName("Name")->AsString = "sms";
ADOQuery1->Post();
 

Re:Field cannot be modified error

Thank you for the reply.
It works if the following line is added before the line
ADOQuery1->FieldByName("id")->AsInteger = 2 ;
ADOQuery1->FieldByName("id")->ReadOnly = false;
So
ADOQuery1->Insert();
ADOQuery1->FieldByName("id")->ReadOnly = false;
ADOQuery1->FieldByName("id")->AsInteger = 2 ;
ADOQuery1->FieldByName("Name")->AsString = "sms";
ADOQuery1->Post();
I am using windows xp sp2 which has MDAC 2.8 sp1 and c++ builder 2006.
I had a c++ bulder 5 program using MDAC 2.8 that I am now converting to c++
builder 2006 project.
There are some issues with respect to using server side cursors in MDAC 2.8
sp1.
I get the error "Provider cannot determine the value. Possible reasons: the
record was just created, the default value for the field was not available,
or the user has not set a new value." when using server side cursor with
batch optimistic mode. If I change the cursor to client side then I do not
get the error. The only way I can used the server side cursor without error
is to use it with optimistic lock.
Storing using client side cursor and batch optimistic lock is 11 times
slower compared to server side cursor with optimistic lock for 5000 values.
I have seen that storing using server side cursor with batch optimistic lock
is faster in c++ builder 5 and MDAC 2.8.
How to use the server side cursor with batch optimistic lock in windows xp
sp2 and MDAC 2.8 sp1?
My main intention is to reduce the storing time as I have to store large
number of values.
"Adriano Grandi" < XXXX@XXXXX.COM >wrote in message
Quote

You must use:
ADOQuery1->Insert();
ADOQuery1->FieldByName("id")->AsInteger = 2 ;
ADOQuery1->FieldByName("Name")->AsString = "sms";
ADOQuery1->Post();


 

{smallsort}