mysql 如何存储 图片?如下代码报错,请指正!谢谢(100)

  • 主题发起人 主题发起人 mazheng
  • 开始时间 开始时间
M

mazheng

Unregistered / Unconfirmed
GUEST, unregistred user!
mysql 如何存储 图片?如下代码报错,请指正!谢谢 图片字段为 longblob 类型,图片为bmp格式。 //==============================================================================unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBAccess, MyAccess, StdCtrls, Buttons, MemDS;type TForm1 = class(TForm) con1: TMyConnection; myqry1: TMyQuery; btn1: TBitBtn; procedure btn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);var str:Tmemorystream;begin btn1.Enabled:=false; str:=Tmemorystream.Create; str.LoadFromFile('000.bmp'); try myqry1.SQL.Clear; myqry1.SQL.Text:='select * from whmember'; myqry1.Open; myqry1.Edit; Tblobfield(myqry1.Fields.Fields[myqry1.FieldList.Count-1]).loadfromstream(str); myqry1.Post; showmessage('ok'); finally str.Free; btn1.Enabled:=true; end;end;{---------------------------Debugger Exception Notification---------------------------Project Project1.exe raised exception class EMySqlException with message '#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'J揾嫿w崷剽觳oO?禧耢??
 
str.LoadFromFile('000.bmp');这句之后加上str.position := 0;或者 str.seek(0,0);
 
procedure TForm1.btn1Click(Sender: TObject);var str:Tmemorystream;begin btn1.Enabled:=false; str:=Tmemorystream.Create; str.LoadFromFile('000.bmp'); str.Seek(0,0); try myqry1.SQL.Clear; myqry1.SQL.Text:='select * from whmember;'; myqry1.Open; myqry1.Edit; Tblobfield(myqry1.Fields.Fields[myqry1.FieldList.Count-1]).loadfromstream(str); myqry1.Post; showmessage('ok'); finally str.Free; btn1.Enabled:=true; end;end;问题依旧啊 谢谢
 
是组件问题。http://www.devart.com/forums/viewtopic.php?t=14254&sid=5834d6b88f71e0c5f2f60a8870e4d3a3
 
后退
顶部