Home > Back-end >  Want to upload a file to the SQL SERVER database, and can be downloaded from the data is saved as a
Want to upload a file to the SQL SERVER database, and can be downloaded from the data is saved as a

Time:10-10

Upload a file to the SQL SERVER database, and can be downloaded from the data is saved as a file, upload download progress bar are; Realization of C/S mode through database online upgrade

Some problems:
Cb for the data stream function is not very familiar with
Are not familiar with the incoming data stream,

Did brother can give directions.

Insert how put, for example, if the file is too big need to break down?

CodePudding user response:

CB for database operations, the easiest way is to ADO cough up, don't know why store the files in the database, the original poster is rare this kind of practice

CodePudding user response:

Large files don't directly in the database, the small files can save people, after all is convenient, if the file is very big best deposit is decomposed into a group

CodePudding user response:

Large file is not to say that can't stand, it is not easy to upload download, the best approach is to use a special table, at least two fields, a binary stream data, a field in the flow of the CRC check code, so that we can implement breakpoints after the transfer, when used together

CodePudding user response:

The current mainstream database support large binary data storage, and popular method is a direct deposit, 2 it is to establish a separate FTP, each have advantages and disadvantages

CodePudding user response:

If is a large file using the database is not too good, because the database file IO capacity than the file system of the body,

CodePudding user response:

Small file, is used to update the program.

Several m to m
Intranet, with convenient database, requires no additional deployment FTP, etc

CodePudding user response:



Share a BCB for upload function
 bool __fastcall TForm2: : Upfile (void) 
{
TFileStream * MyFStream;
TFileStream * MyFStream2;
TFileStream * FieldStrm;
TFileStream * Buffer;
Int bufsize=0 xf000;
Int n=0 xf000;//upload file stream 61440 byte each time=$F000
Int Counter;
Int post=0;

MyFStream=new TFileStream (Edit1 - & gt; Text, fmOpenRead);

Counter=MyFStream - & gt; The Size;
MyFStream2=MyFStream;
Byte * fileData;
fileData=https://bbs.csdn.net/topics/new byte [Counter];
The String filename.
String filetype.
Filename=MyFStream - & gt; The FileName.
MyFStream - & gt; Read (fileData, Counter);

AnsiString SQLStr rq;
AnsiString oldver newver, softname tempmem, tempvid, temptime;
AnsiString temppath;
Tempvid=FormatDateTime (" MMDDhhmmss ", Now ());
Efileno - & gt; Text=tempvid;
Oldver=Coldver - & gt; The Text. The Trim ();
Newver=Enewver - & gt; The Text. The Trim ();
Temppath=Efilepath - & gt; The Text. The Trim ();
Efilesize - & gt; Text=Counter;

Softname=Efilename - & gt; The Text;
Tempmem=Mfilememo - & gt; The Text;
Temptime=FormatDateTime (" YYYY - MM - DD hh: MM: ss ", Now ());

SQLStr="insert into Updatesoft (v_id, old_ver new_ver, softname, path, FILESIZE, memo, UPTIEM) values ('" + tempvid + "', '" + oldver +"', '" + newver + "', '" + softname + "', '" + temppath + "', '" + Counter + "', '" + tempmem + "', '" + temptime + ") ";
Form2 - & gt; Memo1 - & gt; Lines - & gt; Add (SQLStr);
If (DM - & gt; ADOConnection - & gt; Connected)
{

If (DM - & gt; QueryExecute (SQLStr))
{
Form2 - & gt; Memo1 - & gt; Lines - & gt; Add (" data into success ");
}

}
AnsiString sSQL;
SSQL. Sprintf (" Select * From Updatesoft Where v_id='% s' ", tempvid);
if(! DM - & gt; QueryOpen (sSQL))
{
ShowMessage (" record not found!" );
return false;
}
if(! DM - & gt; QuerySQL - & gt; FieldByName (" SOFT ") - & gt; IsNull)
{
ShowMessage (" KONG ");
return false;
}
DM - & gt; QuerySQL - & gt; Edit ();


//DM - & gt; ADOQuery1 - & gt; Edit ();
TBlobField * pField=(TBlobField *) DM - & gt; QuerySQL - & gt; FieldByName (" SOFT ");
//pField - & gt; The Assign (fileData);

PField - & gt; LoadFromStream (MyFStream2);
DM - & gt; QuerySQL - & gt; Post ();

MyFStream2 - & gt; Free ().



}

CodePudding user response:

Do you have any problem, it will be, ah, I see a flat knot stick

CodePudding user response:

Database, upload download progress bar

This is a bit difficult to
  • Related