这句错在哪了?SQL语句插入图片 ( 积分: 50 )

  • 主题发起人 主题发起人 fusm_2000
  • 开始时间 开始时间
F

fusm_2000

Unregistered / Unconfirmed
GUEST, unregistred user!
请问一个SQL语句中一个字段有可能插入图片,也有可能不插入图片怎么办?下面一些代码:

if TImage(RzPanel2.Controls).Picture.Graphic <>NIL then
begin
MyJpeg := TJPEGImage.Create;
try
MyJpeg.Assign(TImage(RzPanel2.Controls).Picture.Graphic);
MS := TMemoryStream.Create;
MyJpeg.SaveToStream(MS);
MS.Position := 0;
qurey1.Close;
qurey1.SQL.Clear;
qurey1.SQL.text:='insert into PrintSetInfo(PrintId,Idtype,mywidth,myheight,'+
'mytop,myleft,fontStyle,labelCaption,image)values('+
QuotedStr(gettypeid)+','+QuotedStr(myidtype)+','+QuotedStr(mywidth)+','+
QuotedStr(myheight)+','+QuotedStr(mytop)+','+QuotedStr(myleft)+',' +
QuotedStr(fontStyle)+','+QuotedStr(labelCaption)+','+
':imagepath' +')' ;
TBlobField(qurey1.Parameters.ParamByName('imagepath')).LoadFromStream(MS);
qurey1.ExecSQL; //这里哪出错了
finally
MyJpeg.Free;
end;
 
看不懂,什么叫有可能插入图片,有可能不插入图片

用 ms.size = 0 判断不行吗?
 
procedure TFrm_WBMeetMainDoc.Comm1ReceiveData(Sender: TObject;
Buffer: Pointer; BufferLength: Word);
var
Buf: array[0..64000] of Char;
strMsg: String;
begin
ZeroMemory(@Buf[0], Length(Buf));
if BufferLength > 0 then
begin
CopyMemory(@Buf[0], Buffer, BufferLength);
strMsg := StrPas(Buf);
GetTicketInfo(strMsg);
end;

end;
 
//if TImage(RzPanel2.Controls).Picture.Graphic <>NIL then
// begin
// MyJpeg := TJPEGImage.Create;
// try
// MyJpeg.Assign(TImage(RzPanel2.Controls).Picture.Graphic);
// MS := TMemoryStream.Create;
// MyJpeg.SaveToStream(MS);
// MS.Position := 0;
qurey1.Close;
qurey1.SQL.Clear;
qurey1.SQL.text:='insert into PrintSetInfo(PrintId,Idtype,mywidth,myheight,'+
'mytop,myleft,fontStyle,labelCaption,image)values('+
QuotedStr(gettypeid)+','+QuotedStr(myidtype)+','+QuotedStr(mywidth)+','+
QuotedStr(myheight)+','+QuotedStr(mytop)+','+QuotedStr(myleft)+',' +
QuotedStr(fontStyle)+','+QuotedStr(labelCaption)+','+
':imagepath' +')' ;
if TImage(RzPanel2.Controls).Picture.Graphic <>NIL then
qurey1.Parameters.ParamByName('imagepath').Assign(TImage(RzPanel2.Controls).Picture.Graphic)
else
qurey1.Parameters.ParamByName('imagepath').AsString:='';
qurey1.ExecSQL;
// finally
// MyJpeg.Free;
// end;
 
procedure TForm1.btnSetClick(Sender: TObject);
Var
ms1 : TMemoryStream;
sFileName : String;
begin
if not OpenDialog1.Execute then Exit;
sFileName := OpenDialog1.FileName;
ms1 := TMemoryStream.Create;
Try
ms1.LoadFromFile(sFileName);
ms1.Position := 0;
ADOConnection1.BeginTrans;
try
with ADOQuery1 do begin
Close;
SQL.Text := 'INSERT INTO Demo VALUES(''' + sFileName + ''', :p0)';
ADOQuery1.Parameters[0].LoadFromStream(ms1, ftBlob);
ExecSQL;
end;
ADOConnection1.CommitTrans;
except
ADOConnection1.RollbackTrans;
ShowMessage('Error');
End;
finally
FreeAndNil(ms1);
end;
end;
 
[red][/red][h1][/h1]有个工程中有很多子FORM,我想写个方法,只要调用不同的参数就可以SHOW各个子窗体,
比如我调用一个窗体方法:
If Assigned(Frm_Sys_PlaceMgr) then
begin
Frm_Sys_PlaceMgr.BringToFront;
Exit;
end
else
begin
Frm_Sys_PlaceMgr := TFrm_Sys_PlaceMgr.Create(nil);
try
Frm_Sys_PlaceMgr.Align :=alClient;
Frm_Sys_PlaceMgr.BorderStyle := bsNone;
Frm_Sys_PlaceMgr.Parent := RzPanel2;
Frm_Sys_PlaceMgr.Show;
except
Frm_Sys_PlaceMgr.Free;
end;
end;
请告诉我用一个方法能达到通用调用
 
通过读取流的头部信息来判断是什么类型图片,以及是否是图片.
图片的问题,请参考我以前写的
http://www.delphibbs.com/keylife/iblog_show.asp?xid=27546
 
后退
顶部