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:
Dim Intimagesize as Int64
Dim Strimagetype as String
Dim ImageStream as Stream
' Gets the Size of the Image
Intimagesize = PersonImage.PostedFile.ContentLength
' Gets the Image Type
Strimagetype = PersonImage.PostedFile.ContentType
' Reads the Image
ImageStream = PersonImage.PostedFile.InputStream
Dim imagecontent (intimagesize) as Byte
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