2017-04-26 94 views
-2

我编写一个SQL Server存储过程以在表中插入图像。 我的存储过程@fPhoto数据类型是图像。有一个错误,我命令它错误。我的代码有什么问题?在delphi中使用存储过程在数据库中存储图像

DM.Connection.StartTransaction; 
    DM.SP.StoredProcName := 'ProInsert;1'; 
    DM.SP.PrepareSQL(False); 

    DM.SP.ParamByName('@fPName').Value := NameEdit.Text; 
    DM.SP.ParamByName('@fPUnit').Value := UnitCMB.ItemIndex + 1; 
    DM.SP.ParamByName('@fPType').Value := TypeCMB.ItemIndex + 1; 
    DM.SP.ParamByName('@fPPrice').Value := PriceEdit.Text; 

    if ProImage.Picture.Graphic = nil then 
    (DM.SP.ParamByName('@fPhoto') as TBlobField) .Clear //Error 
    else 
    begin 
     F := (DM.SP.FieldByName('@fPhoto') as TBlobField); 
     S := TStream.Create; 
     try 
     S := DM.SP.CreateBlobStream(F, bmWrite); 
     ProImage.Picture.Graphic.SaveToStream(S); 
     finally 
     S.Free; 
     end; 
    end; 

[dcc32错误] AddProUnit.pas(94):E2010不兼容的类型: 'TUniParam' 和 'TBlobField'

回答

1

您应该使用ParamByName代替FieldByName

随着UniDAC您可以使用LoadFromFileLoadFromStream Blob参数是这样的:

if ProImage.Picture.Graphic <> nil then 
    begin 
    MS := TMemoryStream.Create; 
    try 
    ProImage.Picture.Graphic.SaveToStream(MS); 

    DM.SP.ParamByName('@fPhoto').LoadFromStream(MS, ftGraphic); 
    // OR DM.SP.ParamByName('@fPhoto').LoadFromFile('MyFileAddress', ftGraphic); 
    finally 
    MS.Free 
    end; 
    end; 
相关问题