数据库中图片显示报错 ----'JPEG error #42

kv2002 2004-09-23 02:25:40
代码入下:
var
jpegimage:tjpegimage;
jpegimage1:tjpegimage;

begin
With ADOQuery2 do
begin //3
Close;
SQL.Clear;
SQL.Add('select * from Mon_Transaction ');
SQL.Add('where Trans_Card_No=:pNo');
//Parameters.ParamByName('pTime').Value:=StrToDateTime('2004-9-21 18:35:14');
Parameters.ParamByName('pNo').Value:='11111111113';
Open;
if RecordCount <>0 then
begin
///////////////////// 显示照片 /////////////////////
MasterPicture.Picture.Graphic :=nil;
CarPicture.Picture.Graphic :=nil;
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
jpegimage1 := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(fieldbyname('Trans_Photo_1'));
jpegimage1.Assign(fieldbyname('Trans_Photo_2'));
MasterPicture.Picture.Graphic :=jpegimage;
CarPicture.Picture.Graphic :=jpegimage1;
finally
jpegimage.Free ;
jpegimage1.Free ;
end; //end try
//////////// 显示照片 结束 ////////////////////
end //end if
else
ShowMessage('没记录');
end; //3 end with
end;
问题:
1. 我执行时会出现 JPEG error #42 提示
2.数据库中我有一datetime字段 'Trans_Datetime' 我用如下语句时查不到记录
SQL.Add('select * from Mon_Transaction ');
SQL.Add('where Trans_Card_No=:pNo and Trans_Datetime=:pTime');
Parameters.ParamByName('pTime').Value:=StrToDateTime('2004-9-21 18:35:14');
Parameters.ParamByName('pNo').Value:='11111111113';
Open

事实上这条记录确实存在.
初学delphi,请各位大虾给指点.
...全文
1253 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kv2002 2004-09-26
  • 打赏
  • 举报
回复
我搞定了,代码贴出,供和我一样菜的朋友参考,高手勿笑.
显示图片:
{////////////////////////照片显示///////////////////////////}
ImageQuery.Close;
ImageQuery.SQL.Clear;
ImageQuery.SQL.Add('select Carinfo_MasterPicture,Carinfo_CarPicture from Man_AeonCarInfo where Carinfo_Id=:pID and Carinfo_MasterPicture is not null and Carinfo_CarPicture is not null');
Parameters.ParamByName('psID').Value:=sID;
ImageQuery.Open;
if ImageQuery.RecordCount<>0 then
begin
try
BS:=TMemoryStream.Create();
BS1:=TMemoryStream.Create();
MasterPicture.Picture.Graphic := nil;
MasterPicture.Picture.Graphic :=TJpegImage.Create;
CarPicture.Picture.Graphic := nil;
CarPicture.Picture.Graphic :=TJpegImage.Create;
TBlobField(fieldbyname('Carinfo_MasterPicture')).savetostream(BS);
BS.Position:=0;
TBlobField(fieldbyname('Carinfo_CarPicture')).savetostream(BS1);
BS1.Position:=0;
MasterPicture.Picture.Graphic.LoadFromStream(BS);
CarPicture.Picture.Graphic.LoadFromStream(BS1);
finally
BS.Free;
BS1.Free;
end;
end; //end of if
分送各位帮助的兄弟了,顺祝中秋快乐.
liufuyahong 2004-09-25
  • 打赏
  • 举报
回复
建议不要用Parameter,真接用SQL语句,我也遇到过类似问题,改用SQL语句后,问题解决了.
victor_yang 2004-09-25
  • 打赏
  • 举报
回复
这种提示是说图片是空的,我做过产品图片的模块出现过,用之前判断下stream的size就知道了。
kv2002 2004-09-24
  • 打赏
  • 举报
回复
高手给看看呀
kv2002 2004-09-23
  • 打赏
  • 举报
回复
genesea(johnny) 多些帮忙,但你给的答案都不行呀.
skyma(天马行空) 的方法我试试先.
zcfzcf001 2004-09-23
  • 打赏
  • 举报
回复
skyma(天马行空) ( ) 信誉:100


UP同意
genesea 2004-09-23
  • 打赏
  • 举报
回复
对不起,好像是Parameters.ParamByName('pTime').Value:='''2004-9-21 18:35:14''';
genesea 2004-09-23
  • 打赏
  • 举报
回复
你可以跟踪一下程序,看下
Open;前ADOQuery2里SQL的内容就 知道了
genesea 2004-09-23
  • 打赏
  • 举报
回复
Parameters.ParamByName('pTime').Value:=StrToDateTime('2004-9-21 18:35:14');
直接用
Parameters.ParamByName('pTime').Value:='2004-9-21 18:35:14';
试下
  • 打赏
  • 举报
回复
var
temp :TmemoryStream;
begin
……
……
……
TBLOBFIELD(FeildByName('')).saveToStream(Temp);
temp.position := 0;
image1.picture.loadFromSteam(temp);
end;

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧