procedure TDM_main.AddCustom(ID, IDType, CustomName, Sex,
  ComeFrom, Addr, re, IDCopyFileName:String);
var
  MemoryStream:TMemoryStream;
begin
  with Q_add_custom do
  begin
    Params.ParamValues['ID']:=ID;
    Params.ParamValues['ID_TYPE']:=IDType;
    Params.ParamValues['NAME']:=CustomName;
    Params.ParamValues['SEX']:=Sex;
    Params.ParamValues['COME_FROM']:=ComeFrom;
    Params.ParamValues['ADDR']:=Addr;
    Params.ParamValues['REMARK']:=Re;
    MemoryStream:=TMemoryStream.Create;
    MemoryStream.LoadFromFile(IDCopyFileName);
  ParamByName('ID_COPY').SetBlobData(MemoryStream.Memory,
    MemoryStream.Size);
    ExecSQL;
    MemoryStream.Free;
  end;
end;我想把BMP图片存入SQL SERVER中image字段ID_COPY,可是为什么存不上啊?请高手指点!多谢了!

解决方案 »

  1.   

    TBlobField(adoQryTmp.FieldByName('drimage')).LoadFromStream(ms);
      

  2.   

    procedure TForm1.BitBtn2Click(Sender: TObject);  //保存图片
    var
      ms  :TMemoryStream;
      ext :string;
    begin
      if edtDrNameSp.Text= '' then exit;
      if edtDrNameTy.Text= '' then exit;
      if edtDrNameE.Text= '' then exit;
      if not ImageEn1.IsEmpty then
        begin
          ext:= Extractfileext(OpenPictureDialog1.FileName);
          ms := TMemoryStream.Create;
          try
          try
              if Uppercase(ext)= '.BMP' then
                begin
                  ImageEn1.SaveToStreamBMP(ms);
                end
              else if  (Uppercase(ext)= '.JPG') or (Uppercase(ext)= '.JPEG') then
                begin
                  ImageEn1.SaveToStreamJpeg(ms);
                end;
            adoQryTmp.Active:= false;
            adoQryTmp.SQL.Clear;
            adoQryTmp.SQL.Add('select * from drimages');
            adoQryTmp.Active:= true;
            ms.Position:= 0;
            adoQryTmp.Append;
            adoQryTmp.FieldByName('drNameSp').Value:= Trim(edtDrNameSp.Text);
            adoQryTmp.FieldByName('drNameSpPy').Value:= Trim(edtDrNameSpPy.Text);
            adoQryTmp.FieldByName('drNameTy').Value:= Trim(edtDrNameTy.Text);
            adoQryTmp.FieldByName('drNameTyPy').Value:= Trim(edtDrNameTyPy.Text);
            adoQryTmp.FieldByName('drNameE').Value:= Trim(edtDrNameE.Text);
            TBlobField(adoQryTmp.FieldByName('drimage')).LoadFromStream(ms);
            adoQryTmp.FieldByName('indate').Value:=now;
            adoQryTmp.FieldByName('memo').Value:= RedtMemo.Text;
              if Uppercase(ext)= '.BMP' then
                begin
                  adoQryTmp.FieldByName('isbmp').Value:= 1;
                end
              else if  (Uppercase(ext)= '.JPG') or (Uppercase(ext)= '.JPEG') then
                begin
                  adoQryTmp.FieldByName('isbmp').Value:= 0;
                end;
            adoQryTmp.Post;
            Clearedt;
          finally
            ms.Free;
          end;
          application.MessageBox('图片保存成功!','提示',mb_OK);
          adoQry.Active:= false;
          adoQry.Active:= true;
          except
          on e:exception do
            begin
              application.MessageBox('图片保存失败!','警告!',mb_OK);
            end;
          end;
        end;
    end;参照该自己改改吧。
      

  3.   


    Parameters.ParamByName('ID_COPY').LoadFromStream(_MemoryStream,ftBlob);
      

  4.   

    应用 TBlobField(adoQryTmp.FieldByName('drimage')).LoadFromStream(ms);实现!