Am trying to store my TTreeView
inside SQL Server database table by using the next procedure:
procedure Save;
var
BlobField :TBlobField;
Query:TADOQuery;
Stream:TStream;
begin
Stream := TMemoryStream.Create;
Query := TADOQuery.Create(Self);
Query.SQL.Add('Select * From MyTable') ;
Query.Active := True;
Query.First;
Query.Edit;
BlobField := Query.FieldByName('MyTableField') as TBlobField;
Stream := Query.CreateBlobStream(BlobField, bmWrite);
TreeView1.SaveToStream(Stream);
Query.Refresh;
Query.Free;
Stream.Free;
end;
But every time I am getting the error: DataSet is not in edit or insert mode
.
I'm using Delphi 10.1, Win 10, SQL server 2019.
Change
Query.Refresh;
toQuery.Post;
Also, you need to
Free
the blob stream to finalize writing to the blob field before you thenPost
to commit the new data into the DB.Also, you are leaking an unused
TMemoryStream
object.Try this: