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 the following line of code to insert data into a comment like ftBlob
parameters.ParamByName('comment').Assign(Memo1.Lines);
with the above line of code, it inserts data into the database, but inserts invalid data such as "???5?????????????????????????"
therefore, spending some time on google, replacing the 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 throws an error Collision like Operand: image is incompatible with text
ExecSQL;
except on E:EDatabaseError do
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
source
share