Board index » delphi » Manually created recordset - cannot add record

Manually created recordset - cannot add record

Hi!
I use MS ACCESS + Delphi + ADO, provider is Microsoft.Jet.OLEDB.4.0.
I have to create a recordset manually (a virtual one) and to add records
into it. And after succesful copying structure from the opened one I cannot
add records into it. I do as follows:

var
  ADOCommand1 : TADOCommand;  // visual component

{--------------------------------------------------}

ADOCommand1 is successfully opened. Then:

var
  RS : _recordset;

begin
  ADOCommand1.CommandText := 'select * from TestProtocol';

// I create recordset and copy structure from ADOCommand1
  Rs := ADOCommand1.Execute;

// I try to add record
  Rs.AddNew(VarArrayOf(['Que_ID', 'Ans_ID']), VarArrayOf([1, 1]));

And in this line I have an error:

exception class EOleException with message 'Current Recordset does not
support updating. This may be a limitation of the provider, or of the
selected locktype'

Please tell me where I am wrong. Thank you.

--
WBR, Andrew S. Moiseyev

 

Re:Manually created recordset - cannot add record


For this goal You need use TADOTable instead TADOCommand.

"Andrew Moiseyev" <c...@mail.ru> ???Y/???Y ????? ???Y??:
news:3baec8aa$1_2@dnews...

Quote
> Hi!
> I use MS ACCESS + Delphi + ADO, provider is Microsoft.Jet.OLEDB.4.0.
> I have to create a recordset manually (a virtual one) and to add records
> into it. And after succesful copying structure from the opened one I
cannot
> add records into it. I do as follows:

> var
>   ADOCommand1 : TADOCommand;  // visual component

> {--------------------------------------------------}

> ADOCommand1 is successfully opened. Then:

> var
>   RS : _recordset;

> begin
>   ADOCommand1.CommandText := 'select * from TestProtocol';

> // I create recordset and copy structure from ADOCommand1
>   Rs := ADOCommand1.Execute;

> // I try to add record
>   Rs.AddNew(VarArrayOf(['Que_ID', 'Ans_ID']), VarArrayOf([1, 1]));

> And in this line I have an error:

> exception class EOleException with message 'Current Recordset does not
> support updating. This may be a limitation of the provider, or of the
> selected locktype'

> Please tell me where I am wrong. Thank you.

> --
> WBR, Andrew S. Moiseyev

Re:Manually created recordset - cannot add record


Quote
>exception class EOleException with message 'Current Recordset does not
>support updating. This may be a limitation of the provider, or of the
>selected locktype'

>Please tell me where I am wrong. Thank you.

Ok.  You are wrong to assume a recordset returned from a TAdoCommand is
updateab;e

use a Taddataset for the SQL then use its RecordSet property
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Manually created recordset - cannot add record


Thanx 2 all. The next variant helped - maybe someone will need it:

Uses ADOInt;

procedure TForm1.Button2Click(Sender: TObject);
var
  RecordSet: _RecordSet;
begin
  RecordSet := CoRecordset.Create;
  RecordSet.Fields.Append ('test', adVarChar, 255, adFldIsNullable);
  RecordSet.Open (EmptyParam, EmptyParam, adOpenForwardOnly,
adLockBatchOptimistic, adCmdUnknown);
  RecordSet.AddNew  ( VarArrayOf(['test']), VarArrayOf(['1']));
end;

They say that the following variant also works - but I haven't checked it
yet

Quote
>Is it possible to create an ADOTable or an ADODataSet  in memory and
>populate it without connecting to a database ?

Yes

 JustMemTbl := TADODataset.Create(Self);
  JustMemTbl.CursorLocation := clUseClient;
  JustMemTbl.CursorType := ctDynamic;

{Add a string field}
  fld := TStringField.Create(JustMemTbl);
  fld.Size := 10;
  fld.FieldName := 'Field1';
  fld.DisplayLabel := 'Field1';
  fld.DataSet := JustMemTbl;

{Create table}
  JustMemTbl.CreateDataSet;

{Add Record}
  JustMemTbl.Append;
  JustMemTbl.FieldbyName('Field1').asString := 'Hello';
  JustMemTbl.Post;

--
WBR, Andrew S. Moiseyev

Other Threads