I have a Stored Procedure that takes blob data (VarBinary) as a parameter I can't get it to work with TADOStoredProc though.
The Stored Procedure
ALTER PROCEDURE [dbo].[spAddToSolve] @SolveData VarBinary(max)
AS
BEGIN
INSERT INTO dbo.ToSolve (Data, SolveStatus)
VALUES (@SolveData, 0)
END
Here are the two things I tried.
This first one fails finding the Field, what am I Missing
procedure AddItem(dbCon : TADOConnection; sourcePath : String);
var
addProc : TADOStoredProc;
field : TField;
dataStream : TFileStream;
blobStream : TStream;
begin
if FileExists(sourcePath) then
begin
dataStream := TFileStream.Create(sourcePath, fmOpenREad or fmShareDenyNone);
try
addProc := TADOStoredProc.Create(nil);
addProc.Connection := dbCon;
addProc.ProcedureName := 'spAddToSolve';
field := addProc.FieldByName('@SolveData'); //Field'@SolveData' not found
blobStream := addProc.CreateBlobStream(field, bmWrite);
blobStream.CopyFrom(dataStream, dataStream.Size);
addProc.Open;
finally
addProc.Free();
dataStream.Free();
end;
end;
end;
Not sure how to get the method to work, I don't know how to get the stream data into the param value.
procedure AddItem(dbCon : TADOConnection; sourcePath : String);
var
addProc : TADOStoredProc;
param : TParameter;
field : TField;
dataStream : TFileStream;
begin
if FileExists(sourcePath) then
begin
dataStream := TFileStream.Create(sourcePath, fmOpenREad or fmShareDenyNone);
try
addProc := TADOStoredProc.Create(nil);
addProc.Connection := dbCon;
addProc.ProcedureName := 'spAddToSolve';
param := addProc.Parameters.AddParameter;
param.Name := '@SolveData';
param.DataType := ftBlob;
//not sure what to do next
param.Value := dataStream; //Types are not compatable
addProc.Open;
finally
addProc.Free();
dataStream.Free();
end;
end;
end;
Your second try is on the right track. This should work:
param.DataType := ftBlob;
param.LoadFromStream(dataStream);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.