I want to save and load a text file(.xt) into my table (Fied name :BodyFile as Binary) with Storeprocedure from Delphi.
I Have a code for save and load image and it works as well but i cant change this code for a file.
My code is :
- Code: Select all
var st1 : TStream;
St1 := DTM.my_SP.CreateBlobStream(DTM.my_SP.FieldByName('mypic'), bmRead);
Pic_img.Picture.Bitmap.LoadFromStream(St1);
//and for save ...
FileStrm : TStream;
FileStrm := TMemoryStream.Create;
Pic_img.Picture.Bitmap.SaveToStream(FileStrm);
DTM.my_SP.Parameters.ParamByName('@mypic').LoadFromStream(FileStrm , ftGraphic);
FileStrm.Free;
I changed it like below but it doesnt work and give Access violation error :
- Code: Select all
//--save text file to database
var S : TMemoryStream;
S := TMemoryStream.Create;
try
S.LoadFromFile(FileName_lbl.Caption);
S.Position := 0;
TBlobField(DTM.my_SP.Parameters.ParamByName('@BodyFile')).LoadFromStream(s);
finally
S.Free;
end;
DTM.my_SP.Parameters.ParamByName('@Sample_param').Value := 'Insert';
DTM.my_SP.ExecProc;
//--for read content of file
var MyStream: TStream;
try
MyStream := DTM.my_SP.CreateBlobStream(DTM.my_SP.FieldByName('BodyFile'), bmRead);
Memo1.Lines.LoadFromStream(MyStream);
finally
MyStream.Free;
end;
please help me for save and load files in SQL Server database with SP in Delphi
Kind Regards
Babak a