Save the image to the SQL 2000 Server database

Source: Internet
Author: User
On ASP. NET Web pages, how does one Upload files? How can I use ADO. NET to read an image from a database and display it on a Web page?

Summary
. NET is a new distributed computing platform developed by Microsoft. ASP. NET is a programming model for Web development. This article aims to gain some good experience in developing data-driven ASP. NET Web applications. This application will show you how to save an image to the database and read the image from the database. It uses ADO. NET as the data access mechanism, C # as the programming language, and SQL 2000 Server as the background database.
Overview
Generally, large image files are stored in Web server folders instead of databases. In some examples, taking the banking system as an example, people first make the user's signature into an image file and then save it to the database.
Database mode
In this demonstration, Microsoft's SQL 2000 Server is used as a background database. I used a special data type image. This image data type is used to save images to the database.
Controls used:
System. Web. UI. HtmlControls. HtmlInputFile
System. Web. UI. WebControls. TextBox
System. Web. UI. WebControls. Button
Namespace used:
Using System. Data. SqlClient;
Using System. Drawing;
Using System. Data;
Using System. IO;
Using System. Drawing. Imaging;
Encoding
The HtmlInputFile class can be used to declare an instance using the <input type = "file" runat = "server"/> label. The following example shows a complete ASPX file that allows users to upload image files and descriptions. The OnUpload method writes images and descriptions to the Picture table of the iSense database.
// Source code for saving the image file to the database

Public void OnUpload (Object sender, EventArgs e)
{
// Create a byte [] from the input file
Int len = Upload. PostedFile. ContentLength;
Byte [] pic = new byte [len];
Upload. PostedFile. InputStream. Read (pic, 0, len );
// Insert the image and description to the database
SqlConnection connection = new
SqlConnection (@ "server = INDIAINDIA; database = iSense; uid = sa; pwd = india ");
Try
{
Connection. Open ();
SqlCommand cmd = new SqlCommand ("insert into Image"
+ "(Picture, Comment) values (@ pic, @ text)", connection );

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.