Q&A

  • ms-sql 에 jpg 이미지 저장시..ㅠ.ㅠ
현재 3 tier 로 작업중이구요...
ClientDataSet 으로 작업중입니다...

Timage 에 이미지를 오픈 하고  ms-sql 에 저장해야 하는데...

오라클에서는 문제가 없었는데....ms-sql에서는 오류가 납니다...

ms-sql 2000 이구요...field 는 IMAGE 값으로 되어 있습니다..

상품코드 VACHAR(7),
사진   IMAGE


밑에 소스는 저장시  소스 입니다..  CDS  -> ClientDataSet 입니다.

var
  mem: TMemoryStream;
  bjpg: TJPEGImage;
begin
    with CDS4 do
    begin

        if Active then
        begin

          try
              mem    := TMemoryStream.Create;
              bjpg   := TJPEGImage.Create;

              if  BImageCheck then
              begin
                     BImageCheck := True;
              end
              else
              begin
                  if  Image2.Picture <> nil then
                  begin
                    bjpg.Assign(Image2.Picture);
                    bjpg.SaveToStream(mem);
                    mem.Position := 0;

                    IndexFieldNames := '상품코드';
                    if FindKey([FieldByName('상품코드').AsString]) then Edit
                    else Insert;  

                    FieldByName('상품코드').AsString := Edit7.Text;
                    FieldByName('사진').AsSign(bjpg);                  
                    Post;

                    if ApplyUpdates(0) > 0 then Exit;
                    BImageCheck := False;
                  end;
              end;

          finally
             mem.Free;
             bjpg.Free;
             CDS4.IndexFieldNames := '';
          end;

       end;
    end;
end;

저장시 에러메세지는 'Cannot AsSign a TJPEGImage to a BlobField'  입니다.
1  COMMENTS
  • Profile
    Crazy™ 2005.07.01 05:46
    불러온 이미지파일이 비트맵이면 jpg 로 변환해서 들어갑니다.
    검색해서 찾아보시면 있습니다.

    var
         BitImage  : TBitmap;
         JpegImage : TJPEGImage;
         MS: TMemoryStream;
    begin
         with Query_TEMP do
         begin
              //========================================================= Insert
              Close;
              SQL.Clear;
              SQL.Add('INSERT INTO CCA0051T (EMPECD, SIMAGE, CRTEMP, CRTTIM, UPDEMP, UPDTIM )');
              SQL.Add('VALUES (:EMPECD, :SIMAGE, :CRTEMP, :CRTTIM, :UPDEMP, :UPDTIM)');

              ParamByName( 'EMPECD' ).AsString := dxMemData_MainMEMBER.AsString + ' ';

              if Image_Open.Picture.Graphic is TBitmap then
              begin //===================================================== BMP SAVE
                   BitImage   := TBitmap.Create;
                   MS         := TMemoryStream.Create;

                   MS.Position := 0;
                   if Image_Open.Picture.Graphic = nil then
                   begin
                        ParamByName( 'SIMAGE' ).Assign( Image_Open.Picture.Bitmap );
                   end else begin
                        BitImage.Assign( Image_Open.Picture.Bitmap );
                        BitImage.SaveToStream( MS );
                        ParamByName( 'SIMAGE' ).LoadFromStream( MS, ftBlob );
                   end;
                   BitImage.Destroy;
              end else begin //=========================================== JPEG SAVE
                   JpegImage   := TJPEGImage.Create;
                   MS         := TMemoryStream.Create;

                   MS.Position := 0;
                   if Image_Open.Picture.Graphic = nil then
                   begin
                        ParamByName( 'SIMAGE' ).Assign( Image_Open.Picture.Bitmap );
                   end else begin
                        JPEGImage.Assign( Image_Open.Picture.Graphic );
                        JPEGImage.SaveToStream( MS );
                        ParamByName( 'SIMAGE' ).LoadFromStream( MS, ftBlob );
                   end;
                   JPEGImage.Destroy;
              end;

              ParamByName( 'CRTEMP' ).AsString := gs_UseEmpCd;
              ParamByName( 'CRTTIM' ).AsString := FormatDateTime( 'YYYYMMDDHHMM', now );
              ParamByName( 'UPDEMP' ).AsString := gs_UseEmpCd;
              ParamByName( 'UPDTIM' ).AsString := FormatDateTime( 'YYYYMMDDHHMM', now );

              ExecSQL;

              MS.Destroy;
         end;