With the advent of the Internet era, various Internet-based application systems emerge one after another. Most application systems use image data and need to display images on the user interface. This section describes how to store images in a folder and display them as required. The specific implementation step is to store the additional information of the image path and other records in the database, while the real image file is stored in a folder. This method is a good solution.
This article describes how to implement ASP. NET and SQL Server database image storage.
2. Image Processing Method
There are two ways to process images: ① image data is stored directly on the hard disk in the form of files, and additional information (path, file name, comment…) of the image is saved in the database ...); ② Images are directly stored in the database. The two methods have their own advantages and disadvantages. Saving image files to the database facilitates management and maintenance, while storing them to the hard disk may cause data inconsistency due to accidental deletion of image files: however, it is not easy to modify and edit images in the database, at the same time, it will cause I/O consumption when the database reads data, but it will not cause this problem if it is placed on the hard disk. Therefore, it is recommended that small files be stored in the database for ease of management, while large files cannot be stored in the database. Otherwise, database tables will generate a large number of data file fragments.
3. Image Storage Methods: ASP. NET and SQL Server database image storage
The system uses ASP. NET and SQL Server databases to store images. Store images in the directory specified by the hard disk, and store the relative storage path and other ancillary information of the images in the database. The development platform uses the VB language, and the database access technology uses the OleDb mechanism in ADO. NET as the ADO. NET protocol data access mechanism.
3.1 create a database table
For image storage in the entire image management system, you need to create an image content table (myimg). Its structure is shown in table 1.
3.2 configure the background database
The image management system uses the SQL Server 2000 database. The Code is as follows:
3.3 Add image page
Enter the page to add images and store the images to the database.
3.3.1 page example
Add image page 1.
3.3.2 how to upload images
Click the "Browse" button shown in 1 to bring up the "select file" dialog box for the windows operating system. After selecting the appropriate image, click "open.
Click the Upload File button. If the upload is successful, a prompt message is displayed, along with the relative path of the image.
Copy the relative path of the uploaded image to the "image path" text box. Enter the image title and description, select the column to which the image belongs, and click "Submit.
If the information is successfully written to the database, a message indicating that the image is successfully added is displayed.
3.4 database information used on the page
The add new image page uses the myimg table in the database to write the valid information of the user input image to the table, including all fields in the myimg table.
The above describes the implementation of ASP. NET and SQL Server database image storage. A good solution can make the system more suitable. If you store images directly in the database, the image data is constantly increasing. the database will continue to grow, and the image data will be stored directly to the hard disk in the form of files. save the additional information (path, file name, comment…) of the image record in the database ...), This will reduce the information stored in the database and improve the database access performance.