How to Save an Image in a SQL Server Database?

Written by Balaji B

Most ofrepparttar web applications have a lot of images used in it. These images are usually stored in a web server folder and they are accessed by givingrepparttar 149240 relative path torepparttar 149241 file with respect torepparttar 149242 root folder ofrepparttar 149243 website. .Net beingrepparttar 149244 platform for distributed application now, ASP.Net can be used to store images that are small to be stored in a database like SQL Server 2000 and later versions. For this purposerepparttar 149245 SQL Server database provides a data type called “image” which is used to store images inrepparttar 149246 database.

To access these images stored inrepparttar 149247 database we will be usingrepparttar 149248 ADO.Net classes. To find out how to insert and retrieve an image in torepparttar 149249 SQL Server database, you can create a .aspx page which can have a HTMLInputFile control which is used to selectrepparttar 149250 image file that is to be saved inrepparttar 149251 database. You can also create a textbox control in which you can addrepparttar 149252 image name or some comment or an image id forrepparttar 149253 image saved. Use a button control to uploadrepparttar 149254 image torepparttar 149255 database. Namespaces like System.Data.SqlClient, System.Drawing, System.Data, System.IO, and System.Drawing.Imaging are used in this task.

Inrepparttar 149256 OnClick property ofrepparttar 149257 button you can writerepparttar 149258 following code to upload an image torepparttar 149259 database.

// create a byte[] forrepparttar 149260 image file that is uploaded int imagelen = Upload.PostedFile.ContentLength; byte[] picbyte = new byte[imagelen]; Upload.PostedFile.InputStream.Read (picbyte, 0, imagelen); // Insertrepparttar 149261 image and image id intorepparttar 149262 database SqlConnection conn = new SqlConnection (@"giverepparttar 149263 connection string here..."); try { conn.Open (); SqlCommand cmd = new SqlCommand ("insert into ImageTable " + "(ImageField, ImageID) values (@pic, @imageid)", conn); cmd.Parameters.Add ("@pic", picbyte); cmd.Parameters.Add ("@imageid", lblImageID.Text); cmd.ExecuteNonQuery (); } finally { conn.Close (); }

You can also writerepparttar 149264 above code in a function and call that function inrepparttar 149265 OnClick event ofrepparttar 149266 upload button. The code given above performsrepparttar 149267 following steps inrepparttar 149268 process of inserting an image intorepparttar 149269 database.

I Did Not Know I Could Do That - Nifty Software Tools

Written by David D. Deprice

Sticky Notes

With StickyNote 9.0, you can create beautiful 3D notes on your desktop or send them instantly overrepparttar Internet. StickyNote also enables you to adhere notes to documents or windows AND to attach documents to your note. StickyNote eliminatesrepparttar 148978 clutter and confusion of keeping up withrepparttar 148979 reminders and phone numbers that never seem to be where you left them. Forget jotting down messages and let StickyNote deliver them for you. You can even customize a note's texture, color and priority with a few simple clicks, and you can set an alarm to have notes appear at a certain time or at regular intervals.

Cute Reminder

Withrepparttar 148980 help of Cute Reminder software you can easily create desktop sticky notes and make reminders for an appointment, birthday, phone call, bill payment, meeting, oil change, TV show and other events or tasks. Take a pill reminder, break reminder, gift reminder, etc., and you will never miss anything important. The program automatically tracksrepparttar 148981 history of related events and storesrepparttar 148982 information into archive. Individually colored skins, support for audio files in various formats, schedule, linking files and Web pages to reminders and printing. The user-friendly interface provides comfort at your workplace whether atrepparttar 148983 office or at home.

Cont'd on page 2 ==> © 2005
Terms of Use