将 OleVariant数据保存到数据库(100分)

  • 主题发起人 主题发起人 zouduanke
  • 开始时间 开始时间
Z

zouduanke

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将OleVariant类型的数据data_Tmp(图形文件)保存到binary类型的字段zwsj中
 
Tblobfield
Tstream
 
能不能给出具体的一段代码
 
以下为写操作:

procedure TForm1.Button1Click(Sender: TObject);
var
bs:tblobstream;
begin
table1.insert; // or edit
bs:=tblobstream.create(table1.fieldbyname('b1') as tblobfield,bmwrite);
try
memo1.Lines.savetostream(bs);
finally
bs.free;
table1.Post;
end;
end;

以下为读操作:
procedure TForm1.Button2Click(Sender: TObject);
var bs:tblobstream;
begin
bs:=tblobstream.create(table1.fieldbyname('b1') as tblobfield,bmread);
try
memo1.Lines.loadfromstream(bs);
finally
bs.free;
end;

这个是存字符串,你改下,用STREAM.LOADFROMFILE把文件装入STREAM,再用
savetostream放到字段中去,读取则是逆操作
 
procedure TForm1.HQSJClick(Sender: TObject);
var
Mac_Tmp, Card_Tmp, Cnt_Tmp, Level_Tmp, Pass_Tmp: Integer;
Data_Tmp: OleVariant;
Str_Tmp: TBlobStream;
p: Pointer;
L : Integer;
begin
try
Mac_Tmp:=StrToInt(Trim(Edit4.Text));
except
Mac_Tmp:=1;
end;
try
Card_Tmp:=StrToInt(Trim(Edit7.Text));
except
Card_Tmp:=1;
end;
try
Cnt_Tmp:=StrToInt(Trim(Edit8.Text));
except
Cnt_Tmp:=1;
end;
FK524PXN1.GetEnrollData(Mac_Tmp,Card_Tmp,Cnt_Tmp, Level_Tmp, Data_Tmp, Pass_Tmp);
Edit9.Text:=IntToStr(Level_Tmp);
Edit10.Text:=IntToStr(Pass_Tmp);
if A_C.Active then
A_C.Close;
A_C.Parameters.ParamByName('CardNo').Value:=Card_Tmp;
A_C.Parameters.ParamByName('ZWID').Value:=Cnt_Tmp;
A_C.Open;
if A_C.RecordCount<1 then
begin
A_C.Append;
A_C.FieldByName('CardNo').AsInteger:=Card_Tmp;
A_C.FieldByName('ZWID').AsInteger:=Cnt_Tmp;
A_C.Post;
end;
if A_C.Active then
A_C.Close;
A_C.Parameters.ParamByName('CardNo').Value:=Card_Tmp;
A_C.Parameters.ParamByName('ZWID').Value:=Cnt_Tmp;
A_C.Open;
A_C.Edit;
try
Str_Tmp:=TBlobStream.Create(A_C.FieldByName('TXBM') as TBlobField,bmWrite);
L := VarArrayHighBound(Data_Tmp, 1) - VarArrayLowBound(Data_Tmp, 1) + 1;
p := VarArrayLock(Data_Tmp);
Str_Tmp.Seek(0, soFromBeginning);
Str_Tmp.WriteBuffer(p^, L);

finally
VarArrayUnlock(Data_Tmp);
end;
A_C.Post;



//TBlobField(A_C.FieldByName('TXBM')).LoadFromStream(Str_Tmp);

end;

TXBM是binary类型
出现Invalid argument的错误,请问下应该怎样修改这段代码
 
后退
顶部