开发者

Using TSimpleDataset for multiple purposes

Delphi 2010

I am trying to use TSimpleDataset for multiple purposes.

var
 q: tsimpledataset;
 row: String;
 n: Integer;
begin
 q:=tsimpledataset.create(nil);
 q.connection:= SQLConnection1 ; 
 q.dataset.commandtype:=ctQuery ;
 q.dataset.commandtext:='select lastid from last_id where tablename=:ARow';
 q.Params.Assign(q.Dataset.Params);
 ShowMessage(q.dataset.commandtext);
 row:='accounts';
 q.params[0].asstring:=  row;
  q.open;
 if q.isempty then
  raise exception.create('No matching row found in LAST_ID table.');
 n:=q.fieldbyname('lastid').asinteger +1;
 q.close;
 q.dataset.commandtype:=ctQuery ;
 q.dataset.commandtext:='update last_id set lastid=22';
 q.execute;  //exception Here!
end;

I get the following error开发者_运维知识库 on the q.Execute line:

Missing Data provider or Data packet

Seems to be a problem with the closing of the TSimpleDataset and the reuse of it. It would work if i freed it and recreated it and reassined the properties and new properties to use it for an execute. However, i would like to not have to do that. I would like to be able to close it, and then assign a new CommandText and reuse it.

I have researched and read alot of comments on the internet reagrding not using the buggy TSimpleDataset, to use the three other components instead (ClientDataSet, DataSetProvider and SQLDataSet). You would think that by 2010 Embarcadero would have worked out any issues with the TSimpleDataset.

Is there any workaround other than having to swictch to something other than a TSimpleDataset?

Thanks!


Shouldn't the second commandtype be.

q.DataSet.CommandType := ctUpdate;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜