4
votes

I am working on Delphi 7+ SQL Server 2008 + ADO

I have a table with 4 fields

emp_id integer 
Name varchar(50) 
designation varchar(10) 
comment text

I am trying to insert data from Delphi

 with qryAdoEmployee do
        try
          if not prepared then Prepared := True;
          Parameters.ParamByName('emp_id').Value := 12345;
          Parameters.ParamByName('Name').Value := 'NAME';
          Parameters.ParamByName('designation').Value := 'NEWDesig' ;

so i tried below line of code to insert data into comment of type ftBlob

          parameters.ParamByName('comment').Assign(Memo1.Lines);

with above line of code it is inserting data into database but it is inserting wrong data like "???5?????????????????????????"

so after spending some time on google replaced above line of code with

      Len := Length(Memo1.Lines.Text);
      Stream := TMemoryStream.Create;
      Stream.Write(Len, SizeOf(Len));
      Stream.Write(PChar(Memo1.Lines.Text)^, Len);
      parameters.ParamByName('comment').LoadFromStream(Stream,ftBlob);

above piece of code is throwing error Operand type clash: image is incompatible with text

    ExecSQL;
    except on E:EDatabaseError do 
      MessageDlg(E.Message, mtError, [mbOK], 0);
    end;
1
Simply set parameter Value = Memo1.Textkobik
@kobik : i tried that and it is also giving the same error Operand type clash: image is incompatible with text.DelphiLearner
Is this line correct - parameters.ParamByName('comment').LoadFromStream(Stream,ftBlob); ? as your fieldname is comments textRBA
I have never came across such problem. How do you define your parameters? if its in design time make sure the parameter DataType is ftMemo. or set it via code. e.g. parameters.ParamByName('comment').DataType := ftMemokobik
@kobik : i changed the parameter type to ftMemo and it's working.DelphiLearner

1 Answers

4
votes

SQL Server text type should map to ftMemo in Delphi (not to ftBlob).

If you defined the parameters in design time, make sure the DataType is set to ftMemo, or set it in runtime:

parameters.ParamByName('comment').DataType := ftMemo;

Then simply assignn the parameter Value:

parameters.ParamByName('comment').Value := Memo1.Text;