如何把图片存进ACCESS数据库中 ( 积分: 100 )

  • 主题发起人 主题发起人 colorfish
  • 开始时间 开始时间
C

colorfish

Unregistered / Unconfirmed
GUEST, unregistred user!
如题....
还有,用OPENDIALOG如何把图片打开传到IMAGE控件中
 
if OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
 
存取图片到Access数据库
你可以看看这个
这个 不是 我写的
http://www.2ccc.com/article.asp?articleid=3685
 
你把图片的路径放进access数据库里面,,就行了....调用的时候就像调用平常的字段一样...
 
完整的答案:
If you develop a database related software, then very popular task is to save some files (documents/images/reports/etc) in some BLOB field of table and use these saved data later.

In this tip I want to show how this task could be solved.

To save a file to BLOB:

blob := yourDataset.CreateBlobStream(yourDataset.FieldByName('YOUR_BLOB'), bmWrite);
try
blob.Seek(0, soFromBeginning);

fs := TFileStream.Create('c:/your_name.doc', fmOpenRead orfmShareDenyWrite);
try
blob.CopyFrom(fs, fs.Size)
finally
fs.Free
end;
finally
blob.Free
end;

To load from BLOB:

blob := yourDataset.CreateBlobStream(yourDataset.FieldByName('YOUR_BLOB'), bmRead);
try
blob.Seek(0, soFromBeginning);

with TFileStream.Create('c:/your_name.doc', fmCreate) do
try
CopyFrom(blob, blob.Size)
finally
Free
end;
finally
blob.Free
end;

Using this code you can work with any database engine (BDE/ADO/DAO/ODBC/DBISAM/etc) and any file format (document of MS Word, spreadsheet of MS Excel, bitmap or jpeg pictures, wav-files etc)

更多技巧:
http://www.mytips123.com/categories/Database/
 
后退
顶部