Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2019, 09:54 PM
jocaro jocaro is offline
Member
 
Join Date: Mar 2012
Posts: 31
Default Insert record with blobfield

Hi

Let's see if any of you can help me.
With the following syntax I can insert a record and then update its blob field with the information of a Stream.
My question is if I could do it all in one step (insertion of the record with the information of the key and the blob already loaded) in the first instruction and what would be the syntax.

Thanks for your help.

Quote:
ModuloBaseDatos.TablaNotas.InsertRecord([VariableClave, '']);

ModuloBaseDatos.TablaNotas.Edit;
TBlobField(ModuloBaseDatos.TablaNotas.FieldByName( 'DesNot')).LoadFromStream(StreamDelBlob);
ModuloBaseDatos.TablaNotas.Post;

Last edited by jocaro; 11-24-2019 at 10:03 PM.
Reply With Quote
  #2  
Old 11-25-2019, 01:58 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 200
Default

I would highly suggest you get away from Table components and instead use Query Components. They are much more versatile.

As far as inserting a record into the database with a blob field try something like this:
Code:
var
  Query: TYourQueryType;
begin
  Query := TYourQueryType.Create(nil);
  try
    Query.Connection := YourDBConnector;
    Query.SQL.Text := 'insert into yourtablename   (field1Name, field2Name, etc, blobfieldName) values (:field1Param, :field2Param, :fieldnParam, :blobFieldParam);
    Query.paramByName('field1Param').AsInteger := 5; //(example inserting integer value)
    Query.paramByName('field2Param').AsString := 'Hello World'; //(example inserting string value)
    Query.paramByName('fieldnParam').AsDate := Date; //(example inserting date value)
    Query.ParamByName('blobFieldParam').LoadFromStream(StreamDelBlob, ftBlob);
    Query.ExecSQL; //execute the query DO NOT OPEN IT because it does not return a result set
    //now the database and your Table component are out of synch, so you must refresh the table
    ModuloBaseDatos.TablaNotas.DisableControls;
    try
      ModuloBaseDatos.TablaNotas.Refresh;
    finally
      ModuloBaseDatos.TablaNotas.EnableControls;
    end;
  finally
    Query.Free;
  end;
end;

Last edited by rojam; 11-26-2019 at 01:48 PM.
Reply With Quote
  #3  
Old 11-25-2019, 11:47 PM
jocaro jocaro is offline
Member
 
Join Date: Mar 2012
Posts: 31
Default

Hi rojam.


Thanks for your detailed explanation.


I will study this alternative


Best regards
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:17 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.