怎么样通过sql语句把一个表中的一条图片字段记录insert到另一个表?
TableA中有字段ID,img1,img2
TableB中有字段ID,img1.....如何通过一条sql语句把这个tableA字段img1的图片insert到TableB中img1的新记录中
分不多了,谢谢大家。

解决方案 »

  1.   

    至今没有用SQL语句存图片的解决办法。
      

  2.   

    //通用的BLOB文件存储修改删除程序procedure TForm1.Button1Click(Sender: TObject); //插入
    var
      fs : TFileStream;
      b: TBlobByteData;
    begin
      if ADOQuery1.Active and (not (ADOQuery1.State in [dsInsert, dsEdit])) then
      begin
        ADOQuery1.Insert;
        if OpenDialog1.Execute then
        begin
          ADOConnection1.BeginTrans;
          try
           // ADOQuery1BLOBFIELD.
            ADOQuery1FILENAME.AsString := OpenDialog1.FileName;
            ADOQuery1BLOBFIELD.LoadFromFile(OpenDialog1.FileName);
            //ADOQuery1.GetBlobFieldData(1,ADOQuery1BLOBFIELD);
            StatusBar1.Panels[1].Text := IntToStr(ADOQuery1BLOBFIELD.BlobSize)+'Bytes';
            ADOQuery1.Post;
            ADOConnection1.CommitTrans;
            ShowMessage('Insert file sucess!');
          except
            ADOConnection1.RollbackTrans;
            ADOQuery1.Active := false;
            ADOQuery1.Active := true;
            ShowMessage('Insert file fault!');
          end;
        end;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject); //读取
    var
      FS : TFileStream;
    begin
      if ADOQuery1.Active and not ADOQuery1.IsEmpty then
      begin
        SaveDialog1.FileName := ADOQuery1.FieldByName('FileName').AsString;
        if SaveDialog1.Execute then
        begin
          FS := TFileStream.Create(SaveDialog1.FileName,fmCreate);
          try
            try
              ADOQuery1BLOBFIELD.SaveToStream(FS);
              ShowMessage('Read file sucess!');
            except
              ShowMessage('Read file fault!');
            end;
          finally
            FreeAndNil(FS);
          end;
        end;
      end;
    end;procedure TForm1.Button4Click(Sender: TObject); //删除
    begin
      if ADOQuery1.Active and not ADOQuery1.IsEmpty then
      begin
        ADOConnection1.BeginTrans;
        try       
          ADOQuery1.Delete;
          ADOQuery1.Edit;
          ADOQuery1.Post;
          ADOConnection1.CommitTrans;
          ShowMessage('Delete file sucess!');
        except
          ADOConnection1.RollbackTrans;
          ADOQuery1.Active := false;
          ADOQuery1.Active := true;
          ShowMessage('Delete file fault!');
        end;
      end;
    end;procedure TForm1.Button3Click(Sender: TObject);//更新
    begin
      if ADOQuery1.Active and (not (ADOQuery1.State in [dsInsert, dsEdit])) then
      begin
        //
        if OpenDialog1.Execute then
        begin
          ADOConnection1.BeginTrans;
          try
            ADOQuery1.Edit;
            ADOQuery1BLOBFIELD.LoadFromFile(OpenDialog1.FileName);
            ADOQuery1.Post;
            ADOConnection1.CommitTrans;
            ShowMessage('Update file sucess!');
          except
            ShowMessage('Update file fault!');
            ADOConnection1.RollbackTrans;
          end;
        end;
      end;
    end;
      

  3.   

    //从sql server读出
    procedure TForm1.Button2Click(Sender: TObject);
    var
      s:Tstream;
    begin
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('select images from dwg where id =5');
      ADOQuery1.Prepared;
      ADOQuery1.Open;
      with ADOQuery1 do
        s:=CreateBlobStream(ADOQuery1.FieldByName('images'),bmRead);
      olecontainer2.LoadFromStream(s);
      //olecontainer2.SaveToFile('aaa.dwg');
      s.Free;
    end;
    //写入sql server
    procedure TForm1.Button1Click(Sender: TObject);
    var
      s:TMemorystream;
    begin
      s:=TMemorystream.Create;
      olecontainer1.SaveToStream(s);
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('insert into dwg (images) VALUES (:tmpcad)');
      ADOQuery1.Parameters.ParamByName('tmpcad').LoadFromStream(s,ftBlob);
      ADOQuery1.Prepared;
      ADOQuery1.ExecSQL;
      s.Free;
      showmessage('保存成功!');
    end;