town car ride to ohare Marengo Park Ridge taxi to Midway Naperville south of 95 limo Midway Lincoln Stretch limo rentals Deerfield travel from O'Hare Carpentersville .. Drug testing

How to Save an Image in a SQL Server Database?

Most of the 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 giving the relative path to the file with respect to the root folder of the website. .Net being the 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 purpose the SQL Server database provides a data type called "image" which is used to store images in the database.

To access these images stored in the database we will be using the ADO.Net classes. To find out how to insert and retrieve an image in to the SQL Server database, you can create a .aspx page which can have a HTMLInputFile control which is used to select the image file that is to be saved in the database. You can also create a textbox control in which you can add the image name or some comment or an image id for the image saved. Use a button control to upload the image to the database. Namespaces like System.Data.SqlClient, System.Drawing, System.Data, System.IO, and System.Drawing.Imaging are used in this task.

In the OnClick property of the button you can write the following code to upload an image to the database.

// create a byte[] for the image file that is uploaded
int imagelen = Upload.PostedFile.ContentLength;
byte[] picbyte = new byte[imagelen];
Upload.PostedFile.InputStream.Read (picbyte, 0, imagelen);
// Insert the image and image id into the database
SqlConnection conn = new SqlConnection (@"give the 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 write the above code in a function and call that function in the OnClick event of the upload button. The code given above performs the following steps in the process of inserting an image into the database.

1. Get the content length of the image that is to be uploaded
2. Create a byte[] to store the image
3. Read the input stream of the posted file
4. Create a connection object
5. Open the connection object
6. Create a command object
7. Add parameters to the command object
8. Execute the sql command using the ExecuteNonQuery method of the command object
9. Close the connection object

To retrieve the image from the SQL Database you can perform the following steps.

1. Create a MemoryStream object. The code can be something like, MemoryStream mstream = new MemoryStream ();

2. Create a Connection object

3. Open the connection to the database

4. Create a command object to execute the command to retrieve the image

5. Use the command object's ExecuteScalar method to retrieve the image

6. Cast the output of the ExecuteScalar method to that of byte[] byte[] image = (byte[]) command.ExecuteScalar ();

7. Write the stream mstream.Write (image, 0, image.Length);

8. Create a bitmap object to hold the stream Bitmap bitmap = new Bitmap (stream);

9. Set the content type to "image/gif" Response.ContentType = "image/gif";

10. Use the Save method of the bitmap object to output the image to the OutputStream. bitmap.Save (Response.OutputStream, ImageFormat.Gif);

11. Close the connection

12. Close the stream mstream.Close();

Using the above steps you can retrieve and display the image from the database to the web page.

You can use these algorithms and take advantage of the "image" data type available in the SQLServer 2000 database to store small images that correspond to a particular record in the table of the database. This method of storing avoids the tedious task of tracking the path of the web folder if the images are stored in a web folder.

Visit A Guide to .NET for a complete introduction to .NET framework. Learn about ASP.NET, VB.NET, C# and other related technologies.

limousine chicago service
In The News:

The Boy Scouts of America is trying to recruit a new generation of kids to join its troops with high-energy, high-tech activities that include thrill-inducing zip lines at a new adventure camp, apps and a television show.
The next iPhone or iPad from Apple is surely around the corner, and Google is getting into everything from cloud computing to car making. But what the cards hold for $100 billion behemoth Facebook is far from clear, experts say.
Rumors of the hairy humanoid known variously as the yeti, bigfoot and sasquatch have persisted for decades. Now scientists are hoping to make more of a case for the creature -- with the help of genetic testing, Reuters reported.
Scotty has finally been beamed up. The ashes of the actor James Doohan, who played Scotty on the 1960s television series "Star Trek," were launched to space this morning (May 22) on a SpaceX Falcon 9 rocket.
Cows are a red herring. The most dangerous potential source for methane release lies underneath thinning permafrost and glaciers in the Arctic. Ecologists have just mapped the seeps where methane is bubbling up, and they found more than 150,000 of them.
At a time when black magic was relatively common, two curses involving snakes were cast, one targeting a senator and the other an animal doctor, says a Spanish researcher who has just deciphered the 1,600-year-old curses.
Presidents Barack Obama and Bill Clinton, U2 frontman Bono and more honored the memory of late Apple founder Steve Jobs Monday in New York City at the 16th annual Webby Awards. 
Humans' close relationship to dogs has so far obscured their history so much that it's not yet possible to use genetic data to tease out the details of their domestication, new research indicates.
A Jurassic mom's almost certainly painful death is perfectly preserved in a rare fossil skeleton, one of the many unique items that will go on display in the Houston Museum of Natural Science's $85 million dinosaur hall when it opens to the public June 2. We take a first peek at the exhibit.
A Jurassic Mom's almost certainly painful death is perfectly preserved in a rare fossil skeleton, one of the many unique items that will go on display in the Houston Museum of Natural Science's $85 million dinosaur hall when it opens to the public June 2.
The rise of Kickstarter's crowdsourcing platform means consumers can now vote with their dollars, investing in unique new projects that they believe in, from smartphone watches designed from e-paper to coffee joulies that keep your drink at the perfect temperature. Here are the 12 most funded design projects.
Jodie Foster may have seen proof of alien lands in the 1997 Robert Zemeckis film "Contact," but the real life astronomer the filmmakers based their sci-fi odyssey on didn't find so much as a tentacle.
A first-of-its-kind commercial supply ship rocketed toward the International Space Station following a successful liftoff early Tuesday, opening a new era of dollar-driven spaceflight.
Many scientists say it's just a matter of time before we find evidence it exists, and now, anyone can get in on the hunt -- as long as they have a computer.
The private rocket company SpaceX is officially "go" to make a second try at launching its unmanned Dragon capsule early Tuesday, May 22, from Florida's Space Coast.
The Supreme Court refused Monday to hear an appeal from a Boston University student who was slapped with a $675,000 penalty for illegally downloading 31 songs and sharing them on the internet.
The European Union has given Google "a matter of weeks" to propose remedies to antitrust concerns arising from its alleged dominant position in the online search market.
A Maryland student was awarded the top prize at the Intel International Science and Engineering Fair on Friday for developing a urine and blood test that detects pancreatic cancer with 90 percent accuracy.
Microsoft recently announced plans to strip the Windows interface to its basics -- flattening surfaces, removing reflections, and scaling back distractions. Here's a brief look at the Windows interface over its 27-year history -- and how it will look tomorrow. 
Microsoft's So.cl social network opened to the public at large this weekend. The experimental research project combines social networking and search, the company said -- and the company swears it's not meant to compete with Google+ or Facebook.

Quick System Restore with ASR Backups

ASR (Automated System Recovery) is a feature available on the... Read More

Virtual Memory - What is It?

I recently got an e-mail asking about virtual memory. The... Read More

Build Your Own Computer

I'm eighty-one years old and I bought my first computer... Read More

Repairing A Corrupt .RAR/.ZIP Archive

Step 1:Open WinRAR and browse to the folder with your... Read More

How To Remove One Operating System from a Dual Boot Windows XP Computer

In Windows Xp, you can install two operating systems on... Read More

Lightning Season: How to Avoid Data Loss

We have just entered the time of year that most... Read More

Password Nightmares

Good Morning Mr. Sampson. Please type in you Personal Identification... Read More

Anti-Skip Protection on Mp3 Players

There have been some questions on anti-skip protection on mp3... Read More

Buying a Home Theater Receiver

Buying a receiver is one of the most important decisions... Read More

The Help Desk

When you think of a help desk, what do you... Read More

How To Have Two (Multiple) Copies Of Windows

Having two operating systems is not as difficult as many... Read More

Wordpress Plugins

Maybe you always wanted a feature that hasn't been available... Read More

How I Started Working With 3D Modeling Programs

So I'll start from the very beginning.One day I was... Read More

Microsoft Great Plains Dexterity Customizations

Microsoft Business Solutions is on the way to popularize it's... Read More

Reliable File and Folder Sharing in Windows Xp

This tip is on sharing files and folders on a... Read More

Learn the Lost Art of Touch Typing

Computers have replaced typewriters, but two-finger, hunt-and-peck typing can never... Read More

Home Electronics: The Facts About Plasma TV

Not so many years ago, homes across the country watched... Read More

5 Simple Ways To Increase Your Computer Speed & Help Your Computer Run More Efficiently!

If you're a computer expert, you'll probably already know about... Read More

Digital Cameras: Hot Gear with the Coolest Features!

Cameras: still known for taking pictures but assumed as digital... Read More

iPod users get the picture

iPod users start to get the picture and it's turning... Read More

What Has A Portable MP3 Player Have To Do With Your Business

Plenty! When we made the decision to be our own... Read More

How to Use SQLXML to Retrieve Data from SQL Server Database?

Using SQL Server 2000 and above versions you can retrieve... Read More

Top 9 Ways To Speed Up Your Surfing & Computing

It seems like fast never quite rates fast enough.No matter... Read More

Temporary Fixes to Spyware, Ad-ware, and Virus Infections

So you've got some spyware, ad-ware, or viruses on your... Read More

Computer Viruses are Bad Luck

OK, so you caught a computer virus and your system... Read More

parking garage led street light costs Pete's produce ..