Board index » delphi » Dataset Not in edit or insert mode

Dataset Not in edit or insert mode

Hi

Can anyone help with this?

The following code seems gives the error message above.

repeat
with datamodule1.Managerstable do
datamodule1.Managerstable.close;
datamodule1.Managerstable.open;
datamodule1.Managerstable.edit;
datamodule1.Managerstable.First;

datamodule1.Managerstable.FieldByName('F1').AsString:='';

until datamodule1.managerstable.eof;

I can open and edit the dataset in another procedure within the unit.

Any ideas

Alex Deacon

 

Re:Dataset Not in edit or insert mode


Hi,

Quote
> repeat
> with datamodule1.Managerstable do
> datamodule1.Managerstable.close;

here you close the table.

Quote
> datamodule1.Managerstable.open;

here you open the table again... why closing it?
the currentrecord is the first record in the table.

Quote
> datamodule1.Managerstable.edit;

here, you set the current record into editmode.

Quote
> datamodule1.Managerstable.First;

here, you scroll to the first record in the resultset, losing the editmode.
Quote

> datamodule1.Managerstable.FieldByName('F1').AsString:='';

here, you try to set a field called 'f1'... ofcourse, this doesn't work.
Quote

> until datamodule1.managerstable.eof;

repeat all of the above until eof is reached...

why not do this:

DataModule1.Managerstable.Open;
while not DataModule1.Managerstable.EOF
do begin
        DataModule1.Managerstable.Edit;
        DataModule1.Managerstable.FieldByName('F1').AsString := '';
        DataModule1.Managerstable.Next;
    end;        

it is faster and it works... or maybe with a query?

good luck!
Martijn

--
Martijn Tonies
http://surf.to/seal97

<none of the text written above has got anything to do with Euro Partners
Informatici BV>

System Development
Euro Partners Informatici BV
http://www.euro-partners.nl

Re:Dataset Not in edit or insert mode


See notes below
--
Remove NOSPAM. from email

box...@clara.net wrote in article <3546ed42.4609...@news.clara.net>...

Quote
> Hi

> Can anyone help with this?

> The following code seems gives the error message above.

> repeat
> with datamodule1.Managerstable do
> datamodule1.Managerstable.close;
> datamodule1.Managerstable.open;
> datamodule1.Managerstable.edit;
> datamodule1.Managerstable.First;

** The First forces an implicit POST so at this point you are NOT IN EDIT
MODE
Quote

> datamodule1.Managerstable.FieldByName('F1').AsString:='';

** Now you are trying to set a value but the previous line put you in
Browse

Quote

> until datamodule1.managerstable.eof;

** apparently, you are try to blank out the F1 field in the entire table
with datamodule1.Managerstable do
 begin
  Open; //if already open doesn't do anything
  First; //if was already open ensures top of table
  while not EOF do
   begin
    Edit;
    FieldByName('F1').AsString := '';
    Post;
    Next; //don't forget this line or your toast (as in infinite loop)
   end;
 end;

Actually an easier way to do this is with a tQuery
Query.Sql.Text := 'update tablenamehere set F1 = ""';
Query.ExecSQL;

Much faster (especially on a server)

Quote

> I can open and edit the dataset in another procedure within the unit.

> Any ideas

> Alex Deacon

Other Threads