Description Why save the file to the database? There are many reasons, the most straightforward is, after putting the file into the database, you can make a better management, especially text files, pictures, etc. If you don't use the database, it is difficult to do effectively when it is huge. the difference. In particular, it is necessary to make some applications related to text, and put all the files in the database is the best choice. The processing, search, etc. of the text can directly utilize some of the functions of the database, which can be truly effective management. . This paper is primarily targeted by text based files, such as Word, etc., but actually modify the program, you can upload all file types. Data Sheet Structure Now, let's see the database table structure of the file, here, we give the standard SQL statement for the establishment table: Create Table TBLBOOKSUPLOAD (DOCID INT NULL Identity Primory Key, DOCTILE VARCHAR (200), DOC Image, DOCTYPE VARCHAR (50) EntryDate DateTime Default getdate ()) In the above statement, we see that the data table TBLbooksupload contains five fields: Field Docid is the key field of the table, the data record number; Field DOCTITLE is used to briefly describe the file If you upload the text file, we generally set it to the file title, image, program, etc., set it to the image, the program's brief introduction; the field DOC is the field used to store the files we uploaded, note that the DOC field Set to the Image Category; Field Doctype is used to save the type of our upload file, may we why should we want this field? In fact, this field is very important. When the user gets data from the database, this field will be used to specify the category of data in the data field DOC, then the browser determines the data presented to the user according to this field; the field datetime is A time field, we can see the value of the field taken from the current date of the server. Here is the stored procedure inserted into the data. Let's see the specific code: create procedure usp_booksuploadfile @title varchar (200), @doc Image, @DOCTY VARCHAR (4) AS Insert TBLBOOKSUPLOAD (DOCTITLE, DOC, DOCTYPE) VALUES (@ title, @ DOC, @ doctype) Go Uploading the steps Now, let's learn from the text to the specific steps of the upload file to the database, then implement it from the code: First, get the uploaded file from the client, then we put it in Data flow; second, server-side read data stream, then save it to cache; Save the cache data to the database; now, let's see how these functions are implemented in the program. The first step of the first step, first we have to implement the user freely select the file in the browser side, then upload, the user selects the file, of course, it is required to standard Windows, so we use the FORM File file component to select files to users .
Note that because the file is uploaded, it should be set to: Multipart / Form-Data when the Form's property is set, so that the file can be uploaded correctly. Below is the main code of the upload page: