2

我将一些信息存储到我的 Access 数据库中,一个参数是一个 BLOB 字段,在这种情况下是一个图像,加载到一个 Timage 中。

我正在使用此代码来保存它:

var
AStream : TMemoryStream;
begin
AStream := TMemoryStream.Create;
  try
Image1.Picture.Graphic.SaveToStream(AStream);
AStream.Position := 0;
if Adotable1.Active then
begin
  Adotable1.Edit;
  TBlobField(Adotable1.FieldByName('Termograma')).LoadFromStream(AStream);
  Adotable1.Post;
end;
  finally
    AStream.Free;

adotable1.Append;
adotable1['Data']:= datetimepicker1.Date;
adotable1['Temax']:= edit4.Text;
adotable1['Temin']:= edit5.Text;
adotable1['Descrição da Posição']:= memo1.Text;
adotable1['Comentários']:= memo2.Text;
adotable1.Post;

但我也有其他信息,我通过单击“附加”部分等同一个按钮来存储。

发生的情况是,当我按下保存按钮时,此信息不会存储在数据库中的相同 ID 中。

我该如何纠正这个问题?

4

1 回答 1

5

您正在编辑当前记录,将图像保存到其中,添加新记录,并将其余信息保存到该新记录中。我认为您打算添加一条全新的记录,将图像和数据添加到该新记录中,然后保存这些更改。

试试这个:

var
  AStream : TMemoryStream;
begin
  if not AdoTable1.Active then
    AdoTable1.Open;

  Adotable1.Append;

  AStream := TMemoryStream.Create;
  try
    Image1.Picture.Graphic.SaveToStream(AStream);
    AStream.Position := 0;
    TBlobField(Adotable1.FieldByName('Termograma')).LoadFromStream(AStream);
  finally
    AStream.Free;
  end;

  adotable1['Data']:= datetimepicker1.Date;
  adotable1['Temax']:= edit4.Text;
  adotable1['Temin']:= edit5.Text;
  adotable1['Descrição da Posição']:= memo1.Text;
  adotable1['Comentários']:= memo2.Text;
  adotable1.Post;
end;
于 2013-02-03T23:14:04.313 回答