Implementation of ASP. NET and SQL Server database image storage

Source: Internet
Author: User

1 Introduction

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.

4 Conclusion

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.

  1. ASP. NET database image storage to Sql2000
  2. Implementation of ASP. NET database Image Upload and reading
  3. Analysis on adding watermarks to Images Using ASP. NET (VB)
  4. Several Methods for quick processing of. NET Images
  5. ASP. NET uploads images to the database and displays images

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.