Introduced
There may be a lot of times when we need to store pictures in the database. In some applications, we may have some sensitive information, because the things stored in the file system, will be easily stolen by some users, so this data can not be stored in the file system.
In this article, we will discuss how to deposit pictures into Sql2000.
In this article we can learn from the following aspects of knowledge:
1. Necessary conditions for inserting pictures
2. Using streaming objects
3. Find the size and type of pictures you want to upload
4. How to use the InputStream method?
necessary conditions for inserting pictures
Before we start uploading, there are two important things we need to do:
The enctype attribute of the #form tag should be set to Enctype= "Multipart/form-data"
# requires a <input type=file> form to enable the user to select the files they want to upload, and we need to import the System.IO namespace to process the stream objects
Apply the above three points to the ASPX page. At the same time we need to prepare the following for SQL Server.
# tables that require a field with at least one picture type
# If we have another field with a variable character type to store the picture type, that would be better.
Now we have a SQL table (a field that contains an image data type) and a <input type=file> tag. Of course we have to prepare the submit button so that the user submits it after selecting the picture. In the OnClick event of this button, we need to read the contents of the selected picture and then save it in the table. Let's take a look at this onclick event first.
Code for the OnClick event of the submit button: