How to load binary files to SQL Server?
Posted: Sat 02 Feb 2019 02:28
Hello everyone. I'm migrating from FireDAC to UniDAC and I need to know all necessary steps to load binary files to SQL Server Database.
I currently do it this way on FireDAC using TFDQuery:
//Some code before ....
FDQuery1.SQL.Clear;
FDQuery1.Params.Clear;
FDQuery1.SQL.Add('INSERT INTO MY_TABLE VALUES (:pVarbinaryMaxField)');
FDQuery1.Params.CreateParam(ftBlob, 'pVarbinaryMaxField', ptInput).SetStream(MyMemoryStream, ftBlob);
FDQuery1.ExecSQL;
//Some code after......
With TFDQuery:
//Some code before.....
FDTable1.Append;
MyBlobStream := FDTable1.CreateBlobStream(FDTable1.FieldByName('VARBINARY_FIELD'), bmWrite);
MyBlobStream.CopyForm(MyMemoryStream, 0);
MyBlobStream.Free; //This is necessary on FireDAC
FDTable1.Post;
//Some code after......
Thanks for your help.
I currently do it this way on FireDAC using TFDQuery:
//Some code before ....
FDQuery1.SQL.Clear;
FDQuery1.Params.Clear;
FDQuery1.SQL.Add('INSERT INTO MY_TABLE VALUES (:pVarbinaryMaxField)');
FDQuery1.Params.CreateParam(ftBlob, 'pVarbinaryMaxField', ptInput).SetStream(MyMemoryStream, ftBlob);
FDQuery1.ExecSQL;
//Some code after......
With TFDQuery:
//Some code before.....
FDTable1.Append;
MyBlobStream := FDTable1.CreateBlobStream(FDTable1.FieldByName('VARBINARY_FIELD'), bmWrite);
MyBlobStream.CopyForm(MyMemoryStream, 0);
MyBlobStream.Free; //This is necessary on FireDAC
FDTable1.Post;
//Some code after......
Thanks for your help.