欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

如何使用delphi将Clientdataset的Delta保存到数据库中

程序员文章站 2022-04-04 13:12:55
...
[delphi]
 view plain copy
//ATableName-表名, AKeyField-主键,多个主键用;隔开,如 ;pid;times;  from:unit HlsImplBase;
[delphi] view plain copy
function THlsImplBase.UpdateTableData(ATableName, AKeyField: AnsiString; var AData: Variant): Boolean;  
var
  LSql: string;  
  LDataSet: TDataSet;  
  LProvider:  TProvider;  
  LErrCount: Integer;  
  I: Integer;  
begin
  Result := False;  
  if ATableName = '' then Exit;  
  if AKeyField = '' then Exit;  
  LSql := 'select * from ' + ATableName + ' where 1 = 2';  
  LDataSet := CreateDataSet(LSql);  
  if not Assigned(LDataSet) then Exit;  
  LProvider := TProvider.Create(nil);  
  LProvider.UpdateMode := upWhereKeyOnly;  
  LProvider.DataSet := LDataSet;  
  AKeyField := LowerCase(AKeyField);  
  for I := 0 to LDataSet.FieldCount - 1 do
  begin
    if (LowerCase(LDataSet.Fields[I].FieldName) = AKeyField) or
        (Pos(';' + LowerCase(LDataSet.Fields[I].FieldName) + ';', AKeyField) > 0) then
      LDataSet.Fields[I].ProviderFlags := LDataSet.Fields[I].ProviderFlags + [pfInKey]  
    else
      LDataSet.Fields[I].ProviderFlags := [];  
  end;  
  try
    try
      LProvider.ApplyUpdates(AData, -1, LErrCount);  
    except
    end;  
    Result := LErrCount = 0;  
  finally
    LDataSet.Free;  
    LProvider.Free;  
  end;  
end;

以上就是如何使用delphi将Clientdataset的Delta保存到数据库中的详细内容,更多请关注其它相关文章!