How to add files into SQL2000 as records |
|
houyu73
一般會員 ![]() ![]() 發表:2 回覆:0 積分:0 註冊:2003-05-17 發送簡訊給我 |
******** How to add files into SQL2000 as records ***********
* *
* Writed by Houyu Xi'an China *
* *
************************************************************* *************************************************************
Why to add files into SQL2000 as records ?
*************************************************************
I always download many files from internet,These files
incloude *.htm,*.mp3,*.txt,*.wav,*.midi,*.exe,and many other
types.
I don't want save them into folders by types or add to zips,
because it's not easy to manage and search.
At 2003/0517 morning,I do it seccessful!
Let's share my experience.
************************************************************* *************************************************************
How to do it ?
*************************************************************
1.Create table in SQL2000.
table mytest
field1 filename char 40
field2 myfile image (Be sure you can visit it,then do next operations.)
*************************************************************
2.Program with Delphi. a project with follow componet Form1--->(face to user) ADOConnection1--->(link to datebase)
ADOTable1--->(link to datebase)
DataSource1--->(link to datebase) DBGrid1--->(to view result)
OpenDialog1--->(to get filename to save)
Buttons1--->"save file to datebase"
Buttons2--->"load file from db to disk"
Buttons3--->"exit"
*************************************************************
then next is the important two parts:
*************************************************************
procedure TForm1.Button1Click(Sender: TObject);
var
strm1:TStream;
strm2:TMemoryStream;
begin
OpenDialog1.Execute;
strm2:=TMemoryStream.Create;
strm2.LoadFromFile(OpenDialog1.FileName);
ADOTable1.Insert;
strm1:= ADOTable1.CreateBlobStream(ADOTable1.Fields[1] , bmReadWrite);
strm1.CopyFrom(strm2,strm2.Size);
ADOTable1.Fields[0].AsString:=OpenDialog1.FileName;
strm1.free;
strm2.Free;
ADOTable1.Post;
end;
*************************************************************
procedure TForm1.Button2Click(Sender: TObject);
var
strm1:TStream;
strm2:TMemoryStream;
Filename:string;
begin
strm2:=TMemoryStream.Create;
ADOTable1.Edit;
Filename:=ADOTable1.Fields[1].AsString;
strm1:= ADOTable1.CreateBlobStream(ADOTable1.Fields[1] , bmReadWrite);
strm2.CopyFrom(strm1,strm1.Size);
strm2.SaveToFile(Filename);
strm1.free;
strm2.Free;
ADOTable1.Post;
end;
************************************************************* *************************************************************
My Program environment
win2000 server SQL2000 Delphi 6 Others
I haven't to test too larger files to save into SQL2000, but
the program have fit me.
I will add some fields as time,filetype,and add some search,
sort function.
I wish my experience will useful to you. Bye!
houyu73@yahoo.com.cn
houyu73@hotmail.com
*************************************************************
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |