SQLDialect为3时,使用FIBDataset,怎么成了只读数据集呢?
时间:2011-03-14 来源:fyen
var ADOQ: TADOQuery; pFIBDatabase1: TpFIBDatabase; pFIBTransaction1, pFIBTransaction2: TpFIBTransaction; pFIBDataSet1: TpFIBDataSet; I: integer; FContent, FSolution: TStream; begin ADOQ:= TADOQuery.Create(nil); ADOQ.ConnectionString:= format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False',[Fmdbfile]); ADOQ.SQL.Text:= 'select * from tbtopic'; ADOQ.Open; pFIBDatabase1:= TpFIBDatabase.Create(nil); pFIBTransaction1:= TpFIBTransaction.Create(nil); pFIBTransaction2:= TpFIBTransaction.Create(nil); pFIBDataSet1:= TpFIBDataSet.Create(nil); pFIBTransaction1.TRParams.Add('read'); pFIBTransaction1.TRParams.Add('nowait'); pFIBTransaction1.TRParams.Add('rec_version'); pFIBTransaction1.TRParams.Add('read_committed'); pFIBTransaction2.TRParams.Add('write'); pFIBTransaction2.TRParams.Add('nowait'); pFIBTransaction2.TRParams.Add('concurrency'); pFIBDatabase1.DefaultTransaction:= pFIBTransaction1; pFIBDatabase1.DefaultUpdateTransaction:= pFIBTransaction2; pFIBDatabase1.DBName:= Ffdbfile; pFIBDatabase1.ConnectParams.UserName:= 'sysdba'; pFIBDatabase1.ConnectParams.Password:= 'masterkey'; pFIBDatabase1.ConnectParams.CharSet:= 'gb18030'; pFIBDatabase1.SQLDialect:= 3; pFIBDatabase1.LibraryName:= 'fbclient.dll'; pFIBDatabase1.Connected:= true; //pFIBDatabase1.ReadOnly; pFIBDataSet1.Database:= pFIBDatabase1; pFIBDataSet1.AutoCommit:= true; pFIBDataSet1.AutoUpdateOptions.AutoReWriteSqls:= True; pFIBDataSet1.AutoUpdateOptions.CanChangeSQLs:= True; pFIBDataSet1.AutoUpdateOptions.UpdateOnlyModifiedFields:= True; pFIBDataSet1.AutoUpdateOptions.UpdateTableName:= 'tbtopic'; pFIBDataSet1.AutoUpdateOptions.KeyFieldList.Add('CODETOPIC'); pFIBDataSet1.SelectSQL.Text:='select * from tbtopic'; pFIBDataSet1.Conditions.Clear; pFIBDataSet1.Conditions.AddCondition('1<>1', '1=2', true);//返回空表 pFIBDataSet1.ApplyConditions(true); try TForm9(FForm).btn5.Enabled:= False; FCount:= ADOQ.RecordCount; for I:= 0 to FCount - 1 do begin FCurID:= I+1; Synchronize(ShowProcess); pFIBDataSet1.Append; //出现错误‘Cannot modify a read-only dataset’ pFIBDataSet1.FieldByName('codetopic').AsString:= ADOQ.FieldByName('code').AsString; pFIBDataSet1.post; ADOQ.next; end; finally ADOQ.close; ADOQ.free; pFIBDatabase1.CloseDataSets; pFIBDatabase1.Close; pFIBDataSet1.free; pFIBTransaction1.Free; pFIBTransaction2.Free; pFIBDatabase1.free; TForm9(FForm).btn5.Enabled:= True; end;
解决:
BDataSet1.AutoUpdateOptions.UpdateTableName:=
'tbtopic';
//改成大写就好了,不知道为啥。
BDataSet1.AutoUpdateOptions.UpdateTableName:=
'TBTOPIC';
相关阅读 更多 +