急!!!!!!图片无法存入数据库 ( 积分: 50 )

  • 主题发起人 主题发起人 lawzhangqi2005
  • 开始时间 开始时间
L

lawzhangqi2005

Unregistered / Unconfirmed
GUEST, unregistred user!
我做一个信息管理系统,用到个人照片存入,但是,在保存按钮的时候有一句话通不过,能否给我解答一下.
============================================
procedure TForm5.BitBtn5Click(Sender: TObject);
var
strm: TMemoryStream;
ext: String;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件的扩展名
strm := tmemorystream.Create;
try
image1.Picture.Graphic.SaveToStream(strm);
datam.ADOcpxxsr.Edit;
strm.Position:=0;
TBlobField(datam.ADOcpxxsr.FieldByName('myimage')).LoadFromStream(strm);
if uppercase(ext) = '.BMP' then
datam.ADOcpxxsr.FieldByName('isbmp').Value := 1 //BMP型图像数据
else
if (uppercase(ext) = '.JPG') Then
datam.ADOcpxxsr.FieldByName('isbmp').Value := 0; //JPEG型图像数据
datam.ADOcpxxsr.Post;
finally
strm.Free ; //笔者发现如strm采用tblobstream类,程序运行到该语句会出现问题
Application.MessageBox('保存成功,谢谢使用!','提示',MB_ICONASTERISk+MB_OK);
end;
end;
end;
 
我做一个信息管理系统,用到个人照片存入,但是,在保存按钮的时候有一句话通不过,能否给我解答一下.
============================================
procedure TForm5.BitBtn5Click(Sender: TObject);
var
strm: TMemoryStream;
ext: String;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件的扩展名
strm := tmemorystream.Create;
try
image1.Picture.Graphic.SaveToStream(strm);
datam.ADOcpxxsr.Edit;
strm.Position:=0;
TBlobField(datam.ADOcpxxsr.FieldByName('myimage')).LoadFromStream(strm);
if uppercase(ext) = '.BMP' then
datam.ADOcpxxsr.FieldByName('isbmp').Value := 1 //BMP型图像数据
else
if (uppercase(ext) = '.JPG') Then
datam.ADOcpxxsr.FieldByName('isbmp').Value := 0; //JPEG型图像数据
datam.ADOcpxxsr.Post;
finally
strm.Free ; //笔者发现如strm采用tblobstream类,程序运行到该语句会出现问题
Application.MessageBox('保存成功,谢谢使用!','提示',MB_ICONASTERISk+MB_OK);
end;
end;
end;
 
TBlobField(datam.ADOcpxxsr.FieldByName('myimage')).LoadFromStream(strm);通不过
 
strm.Position:=0;
改为
BinStream.Seek(0, soFromBeginning);
 
还是不行呀
 
把image1.Picture.Graphic.SaveToStream(strm);
改成image1.picture.savetostream(strm)试试看
 
Stream:TFileStream;
这样没有问题
 
datam.ADOcpxxsr.FieldByName('myimage')
改成这样试试
datam.ADOcpxxsrmyimage.loadfromStream(strm)
也就是说,把字段变成固定的
 
先Free,再Post看看
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
794
import
I
I
回复
0
查看
594
import
I
后退
顶部