我想知道为什么我的clientDataSet上发布的数据没有使用applyUpdates更新到mysql数据库表。
我正在处理两个数据库。
-
db1.customerTable1:没有问题,主键位于“listid”>cds.append>cds.applyUpdates
-
db2.customerTable2:有问题时,主键位于'guid'>cds.edit>cds.applyUpdates。
我在db2.customerTable2上添加了带有“listid”的主键,但仍然不起作用。
在代码下面,我正在处理。
procedure TfrmMain.spbExportClick(Sender: TObject);
var
Guid , VarAccountId, VarListSasId, VarListDspId : Variant;
Status : String;
begin
with dm.dmForm do
begin
cdsCustomer2.first;
while not cdsCustomer2.eof do
begin
//variable data for CDS.Customer1.AllFields
Guid := cdsCustomer2.FieldByName ('Guid').AsString;
VarAccountId := cdsCustomer2.FieldByName('ListID').AsString;
VarListSasId := cdsCustomer2.FieldByName('FullName').AsString;
VarListDspId := cdsCustomer2.FieldByName('Name').AsString;
Status := 'Out';
//posting to CDS.Customer1.AllFields
cdsCustomer1.DisableControls;
cdsCustomer1.Append;
cdsCustomer1.FieldByName('GUID').AsString := Guid;
cdsCustomer1.FieldByName('AccountId').AsString := VarAccountId;
cdsCustomer1.FieldByName('ListSasID').AsString := VarListSasId;
cdsCustomer1.FieldByName('ListDspID').AsString := VarListDspId;
cdsCustomer1.FieldByName('Status').AsString := Status;
cdsCustomer1.EnableControls;
cdsCustomer1.Fields[1].ProviderFlags := [pfInKey];
cdsCustomer1.Post;
//posting Guid value back to CDS.Customer2
if cdsCustomer2.locate('ListID', VarAccountId, []) then
begin
cdsCustomer2.DisableControls;
cdsCustomer2.Edit;
cdsCustomer2.FieldByName('ExternalGUID').AsString := Guid;
cdsCustomer2.EnableControls;
cdsCustomer2.Fields[0].ProviderFlags := [pfInKey];
cdsCustomer2.Post;
end;
cdsCustomer2.Next;
end;
//ApplyUpdates to mysql Customer1.Table and Customer2.Table
cdsCustomer1.ApplyUpdates(-1);
cdsCustomer2.ApplyUpdates(-1);
end;
end;
我希望这些代码可以像数据库1一样简单地发布到我的mysql数据库2。除了发布DB2的CDSCustomer2之外,所有内容都可以发布到两个客户端数据集。
如果我遗漏了一些你可能需要的信息,请告诉我。
附笔。
下面是数据库结构:
uniconnection->mysqluniprovider->uniquery->datasetprovider->clientdataset->datasource->dbgrid