zoukankan      html  css  js  c++  java
  • 将结构体存入Access数据库

    懒得修改了。参数里应该再加一个字段名称,有兴趣的修改一下。。。目前是根据VersionNO来判断,读的时候也可以根据数据库中流的长度来比较。。最好是通过外界手段。。自己控制吧。。。

    只要是连续内存的东西,都可以拿来存...

     1 function TDataModuleDataBase.LoadRecFromDB(const aName, TableName: string;
    2 var Rec; RecSize: Integer): Boolean;
    3 var
    4 MS: TMemoryStream;
    5 begin
    6 Result := False;
    7 if Trim(aName)='' then
    8 Exit;
    9 MS := TMemoryStream.Create;
    10 try
    11 try
    12 ADOConnection.Open;
    13 except
    14 Exit;
    15 end;
    16 with ADOQuery do begin
    17 Active:=False;
    18 SQL.Text:='SELECT * FROM '+ TableName +' WHERE Name='+''''+ aName +'''' + ' and AppVersion=' + '''' + VersionNO + '''';
    19 Active:=True;
    20 if RecordCount <> 1 then
    21 Exit;
    22 with FieldByName('RecOLE') as TBlobField do begin
    23 MS.Position := 0;
    24 SaveToStream(MS);
    25 MS.Position := 0;
    26 MS.Read(Rec, RecSize);
    27 end;
    28 end;
    29 finally
    30 ADOConnection.Close;
    31 MS.Free;
    32 end;
    33 Result := True;
    34 end;
    35
    36 function TDataModuleDataBase.SaveRecToDB(const aName, TableName: string;
    37 var Rec; RecSize: Integer): Boolean;
    38 var
    39 MS: TMemoryStream;
    40 begin
    41 Result := False;
    42 MS := TMemoryStream.Create;
    43 try
    44 try
    45 ADOConnection.Open;
    46 except
    47 Exit;
    48 end;
    49 with ADOQuery do begin
    50 Active:=False;
    51 SQL.Clear;
    52 SQL.Text:='SELECT * FROM ' + TableName + ' WHERE Name='+''''+ aName + '''';
    53 Active:=True;
    54 if RecordCount>=1 then
    55 Exit;
    56 Active:=False;
    57 SQL.Text:='SELECT * FROM ' + TableName;
    58 Prepared;
    59 Open;
    60 Append;
    61 FieldByName('Name').Value := aName;
    62 FieldByName('AppVersion').Value := VersionNO;
    63 with FieldByName('RecOLE') as TBlobField do begin
    64 MS.Position := 0;
    65 MS.Write(Rec, RecSize);
    66 MS.Position := 0;
    67 LoadFromStream(MS);
    68 end;
    69 Post;
    70 end;
    71 finally
    72 ADOConnection.Close;
    73 MS.Free;
    74 end;
    75 Result := True;
    76 end;

      

  • 相关阅读:
    docker 如何启动空容器
    dotnet5.0 aspnetcore runtime docker镜像
    abp asp.net core 手动获取容器中的服务
    我把代码写在别人的分支了?别慌,有办法解决
    var重复声明为什么后续声明会被忽略
    flex布局不常用到的属性整理
    微信openID和unionID的区别
    js稀疏数组、密集数组、数组空位、手写数组map方法
    vscode格式化代码换行?试试这个配置
    封装一个公共组件并上传到npm仓库
  • 原文地址:https://www.cnblogs.com/solokey/p/2113333.html
Copyright © 2011-2022 走看看