Control Panel
Forum
Hosting Help
ASP.NET 4 & SQL 2008 Hosting
Resources
Notice
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Silverlight Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
149203
Average new registrations per day (in last 7 days):
122
New Registration:
Open
Register Now
Learn Windows 7:
Best features of the Firefox
In this resource I will give the best features of the Firefox .
Want to become a DBA ?
SQL Server 2008 training courses
- by AspSpider team
Home
»
Resources
»
Save An Image Into SQL Server 2000 Database
ASP.NET
ADO.NET
Web Services
Remoting
Visual Studio 2005
Error Bank
Interview Questions
Tips & Tricks
XML
HTML
Jscript/Javascript
IIS
Windows
General
Submit Resource or code snippet
... and get
surprise gifts
Win Digital camera, ASP.NET Books, Free softwares!!
Save An Image Into SQL Server 2000 Database
29 Nov, 2009
Author:
Doan Minh Tuan
Home
Summary
Normally, images are saved in the web server folder, not in the database; this is for larger file size category. In some cases like, in bank, for example, they scan the user signatures as image files and save that file into the database.
.NET Classes used :
using System.Data.SqlClient;
using System.Drawing;
using System.Data;
using System.IO;
using System.Drawing.Imaging;
Controls used in this application
System.Web.UI.HtmlControls.HtmlInputFile
System.Web.UI.WebControls.TextBox
System.Web.UI.WebControls.Button
Solution with Code
Use the HtmlInputFile class, which you can declare an instance of with an
tag. The following example is a complete ASPX file that lets a user upload an image file and a comment describing the image. The OnUpload method writes the image and the comment to a table named Pictures in a SQL Server database named iSense.
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 comment into the database
SqlConnection connection = new
SqlConnection (@server=INDIA\INDIA;database=iSense;uid=sa;pwd=india);
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand (insert into Image
+ (Picture, Comment) values (@pic, @text), connection);
cmd.Parameters.Add (@pic, pic);
cmd.Parameters.Add (@text, Comment.Text);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
}
}
Feedbacks about this page from members:
thnx
-
ahmed mohamed magdi
thnx it was very helpfull
(03 Dec 2009)
Submit Feedback
View All Feedbacks
Advertise
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies Pvt Ltd.
All Rights Reserved.