Home > Database > Mysql Tutorial > body text

How to save Delta of Clientdataset to database using delphi

一个新手
Release: 2017-09-19 09:50:05
Original
2737 people have browsed it

[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;
Copy after login

The above is the detailed content of How to save Delta of Clientdataset to database using delphi. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template