Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    4

    Unanswered: Insert JPEG into BLOB error, Help me please.

    I used Delphi.
    This work well with MYSQL but error with DB2.

    //===================================//
    Function TfrmMainScanPict.SavePict(Qry: TADOQuery): String;
    Var
    hn,cPath,s2:string;
    fS : TFileStream;
    begin
    Result:='Start';
    hn:=Trim(ListBox1.Items[0]);
    cPath:='C:\TempScan.JPG';

    fs:=TFileStream.Create(cPath, fmOpenRead);

    Try
    s2:='select OP_HN,PIC_AUTO,PIC_RESULT from LAB_RESULT_PICT'
    +' WHERE OP_HN='''+HN+'''';
    Qry.Close;
    Qry.SQL.Clear;
    Qry.SQL.Add(s2);
    Qry.Open;
    Qry.Insert;
    Qry.FieldByName('OP_HN').AsString:=HN;
    Qry.FieldByName('PIC_AUTO').AsInteger:=Qry.RecordC ount+1;
    Qry.FieldByName('PIC_DATETIME').AsDateTime:=Now;
    TBlobField(Qry.FieldByName('PIC_RESULT')).LoadFrom Stream(fs);
    Try
    Qry.Post; // Error occure here said = 0
    Except on E:Exception do
    Result:= E.Message;
    End;
    Result:='Success';
    Finally
    fs.Free;
    End;
    end;
    //==================================//

    database structure
    ==============
    CREATE TABLE LAB_RESULT_PICT(
    OP_HN CHAR(13) NOT NULL'
    ,PIC_AUTO INTEGER NOT NULL'
    ,PIC_DATETIME TIMESTAMP WITH DEFAULT CURRENT TIMESTAMP
    ,PIC_RESULT BLOB(1024)'
    ,CONSTRAINT PK_LABRESPICT1 PRIMARY KEY(OP_HN,PIC_AUTO))
    Last edited by paracet2000; 09-15-10 at 09:42.

  2. #2
    Join Date
    Sep 2010
    Posts
    4

    Error picture

    Error picture attachDb2 image jpeg.bmp

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Are you trying to assign values to the result of a SELECT statement? That's not how it should be done. Try an UPDATE statement instead.

  4. #4
    Join Date
    Sep 2010
    Posts
    4

    Thank a lot

    This new to me.
    I try to do with your advice it work by use INSERT statement.
    And i went back to test with MYSQL it work too.
    So both SELECT statatement and INSERT statement work with MYSQL,
    but only INSERT work with DB2.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •