Delphi求将image中的图片保存到数据库中代码
发布网友
发布时间:2022-05-13 19:01
我来回答
共2个回答
热心网友
时间:2023-10-21 23:47
procere TSqlHelp.WritePic(AResenderMark,AItem:string;AItemValue:TStream);
begin
if (AResenderMark='') or (AItem='') then exit;
try
if not m_Connection.Connected then m_Connection.Connected:=True;
m_Connection.BeginTrans;
//showmessage(m_Connection.ConnectionString);
with m_QryWork do
begin
Close;
Sql.Clear;
Sql.Add('select * from zxx_sqlhelperData where ResenderMark=:ResenderMark and Item=:Item');
Parameters.ParamByName('ResenderMark').Value:=AResenderMark;
Parameters.ParamByName('Item').Value:=AItem;
Open;
if RecordCount=0 then
begin
append;
FieldByname('ResenderMark').AsString:=AResenderMark;
FieldByName('Item').AsString:=AItem;
TBlobField(FieldByName('ValuePic')).LoadFromStream(AItemValue);
Post;
end
else
begin
Edit;
TBlobField(FieldByName('ValuePic')).Clear;
Post;
Edit;
TBlobField(FieldByName('ValuePic')).LoadFromStream(AItemValue);
Post;
end
end;
m_Connection.CommitTrans;
except
on e:Exception do
begin
m_Connection.RollbackTrans;
//如果发现是线程问题比如到了最大连接数则可递归保存
//if pos('',e.Message)>0 then
//begin
// sleep(300);
// WriteData(AResenderMark,AItem,AItemValue);
// exit;
//end;
messagebox(Application.MainForm.Handle,pchar(e.Message),PAnsiChar(AResenderMark+'提示信息'),MB_OK or MB_ICONWARNING);
end;
end;
end;
热心网友
时间:2023-10-21 23:47
ADOquery1.append;
TBlobField(ADOquery1.FieldByName('filename')).Assign(Image1.Picture.Graphic);
ADOquery1.Post;