明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

怎么使用delphi將Clientdataset的Delta保存到數(shù)據(jù)庫(kù)中

[摘要][delphi]view plain copy//ATableName-表名, AKeyField-主鍵,多個(gè)主鍵用;隔開(kāi),如 ;pid;times; from:unit HlsImplBase;...
[delphi]
 view plain copy
//ATableName-表名, AKeyField-主鍵,多個(gè)主鍵用;隔開(kāi),如 ;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保存到數(shù)據(jù)庫(kù)中的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


學(xué)習(xí)教程快速掌握從入門(mén)到精通的SQL知識(shí)。