with
Query
do
begin
Close
Sql.Clear
Sql.Add('INSERT
INTO
Table
VALUE(:sFileName,:sFileContent)')
ParamByName('sFileName').AsString
OpenDialog.FileName
ParamByName('sFileContent').LoadFromFile(OpenDialog.FileName,ftBlob)
ExecSQL
end2、从数据库中取出文件
with
Query
do
begin
Close
Sql.Clear
Sql.Add('SELECT
*
FROM
Table')
Open
(FieldByName('sFileContent')
AS
TBlobField).SaveToFile
(FieldByName('sFileName').AsString)
end
给你段代码,希望能有所帮助var
Field1:TBlobField
msg:TFMessageWindow
begin
var
Field1:TBlobField
msg:TFMessageWindow
begin
msg := TFMessageWindow.Create(application)
msg.SetMessage('正在保存样板,请稍候...')
qzybody.Open
qzybody.append
try
msg.Show
application.ProcessMessages
Field1:=TBlobField(qzybody.Fieldbyname('object_body'))
Field1.LoadFromFile('')
except
end
qzybody.Post
msg.Close
msg.Free
end
qzy.Post
showmessage('保存成功!')
end
你可以把image控件上的图片存入到磁盘,然后通过上面的方法存入到数据库中.
用下面的方式打开该图片:
var
Field1:TBlobField
filename:string
begin
FMain.dqc.DB_AdoQueryRun(qzybody,'select * from myobjectbody where object_id='+qzy.fieldbyname('object_id').AsString)
if qzybody.RecordCount<1 then
begin
showmessage('数据错误!')
abort
end
else
begin
Field1:=TBlobField(qzybody.Fieldbyname('object_body'))
filename:=FMain.dqc.File_CreateTempFile(qzy.Fieldbyname('object_name').AsString)
Field1.SaveToFile(filename)
FMain.dqc.File_ShellOpen(filename)
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)