How WORD document into the database

Category: Delphi -> VCL/Component Author: xiangdszyj Date: 2014-12-14 10:29:00
 
xiangdszyj
2014-12-14 10:29:00
delphi 7.0

database using sql2000

RT, how to achieve a WORD document to add to the database?
JIAHHUI
2014-12-14 10:46:59

sql := 'UPDATE tab SET BGZW=:file' +
        ' where XTAJBH=''' + case_id + '''';
      execInt := DataModule_sys.ExecLobUpdate(sql, 'file', self.Edit_text.Text);
      //self.Edit_text.Text word 
      // BGZW 
      
      function TDataModule_sys.ExecLobUpdate(sql: string; LobName: string; FileName:
  string): Integer;
begin
  try
    if self.ADOQuery1.Active then
      self.ADOQuery1.Close;
    self.ADOQuery1.Prepared := true;
    self.ADOQuery1.ParamCheck := true;
    self.ADOQuery1.SQL.Text := sql;
    ADOQuery1.Parameters.ParamByName(LobName).LoadFromFile(FileName, ftBlob);
    ADOQuery1.ExecSQL;
    result := self.ADOQuery1.ExecSQL;
  finally
    self.ADOQuery1.Prepared := false;
    self.ADOQuery1.ParamCheck := false;
    self.ADOQuery1.Close;
  end;
 // (ADOQuery1.FieldByName('aaa') as TGraphicField)
end;
qq463840634
2014-12-14 11:06:06
online to find the code that has been tested and modified a bit

use the Image on the database binary field storage, use Stream flow approach.

create a file stream:
Word_FileStream: = TMemoryStream.Create;
Word_FileStream.Position: = 0;

saved to the database Image fields:
Word_FileStream.LoadFromFile ('c: \ wordfile.DOC');
TBlobField (AdoQuery1.FieldByName (Column_Name)). loadfromStream (Word_FileStream);

to read the file from the database local hard disk:
TBlobField (ADOQuery1.FieldByName (Column_Name)). SaveToStream (Word_FileStream);
Word_FileStream.SavetoFile ('c: \ wordfile.DOC');

release of documents Stream:
Word_FileStream.Free;
dillonywl
2014-12-14 11:20:28
you are referring to the data in the document or the document will be saved to the database whole?
oo7ANDY0086853
2014-12-14 11:29:36
I tried it with the following code can solve the problem, but thank you upstairs.
if opendialog1.Execute then begin
with adoquery1 do begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Text: = 'insert into T_test (title, content) Values ​​(: title,: content)';
Parameters.ParamByName ( 'title'). Value: = edit1.Text;
Parameters.ParamByName ('content'). LoadFromFile (opendialog1.filename, ftBlob);
ExecSQL;
end;
end;

record is there, but do not know how to read out the document, content field is the contents of the document, I want to display the contents of memo will be how to achieve ?
QHT54321
2014-12-14 11:38:20
can try TMSWordDocument

this component should be free