<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lyricsal.com</title>
	<atom:link href="http://www.lyricsal.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lyricsal.com</link>
	<description>Get Lyrics for all songs</description>
	<lastBuildDate>Wed, 09 Nov 2011 18:19:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Save and Retrieve Images from the Database using ASP.NET 2.0 and ASP.NET 3.5</title>
		<link>http://www.lyricsal.com/save-and-retrieve-images-from-the-database-using-asp-net-2-0-and-asp-net-3-5/</link>
		<comments>http://www.lyricsal.com/save-and-retrieve-images-from-the-database-using-asp-net-2-0-and-asp-net-3-5/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 18:19:14 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Asp.Net Tasks]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=601</guid>
		<description><![CDATA[At some point or the other, we as ASP.NET developers, have faced the requirement of reading and writing images to the database. We have seen loads of articles floating on the internet which discusses about storing and retrieving images from the database. Some of them are good. However, I have personally found that the solutions [...]]]></description>
			<content:encoded><![CDATA[<div align="justify"><span style="font-family: Verdana; font-size: x-small;">At some point or the other, we as ASP.NET developers, have faced the requirement of reading and writing images to the database. We have seen loads of articles floating on the internet which discusses about storing and retrieving images from the database. Some of them are good. However, I have personally found that the solutions offered are those, where images are displayed in a ‘standalone fashion’; that is on a separate page containing only the image. What if we have to show an online form, with the person’s details and his photo along with it, or for that case, display the image in an ASP.NET server control along with other controls? In this article, we will explore how to store images in the database and then display those images along with the other server controls. </span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">To keep the article simple and easy to understand, we will place only a few controls on the page. I have also <span style="text-decoration: underline;">not</span> covered any validations associated with image control. In this article, we will only discuss how to read and write images into the database, and that would be the focus for this article. If you are interested in discussing validation and other stuff, I would suggest you to browse through the ASP.NET section of this website to view an article that discusses that.</span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">So let us get started. We will first see how to upload an image and then display the uploaded image on the same page. You can extend this sample to create a photo album as well!! I assume you have some knowledge of creating ASP.NET 2.0 websites.</span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">Let us start off by first creating a sample database and adding a table to it. We will call the database ‘Employee’ and the table will be called ‘EmpDetails’. This table will contain an image column along with some other columns. Run the following script in your SQL 2005 Query window (or server explorer) to construct the database and the table.</span></div>
<div><strong><span style="font-size: x-small;"><span style="font-family: Verdana;">Database Script</span></span></strong></div>
<div><span style="font-size: x-small;">CREATE DATABASE [Employee] </span></div>
<div><span style="font-size: x-small;">GO</span></div>
<div><span style="font-size: x-small;">USE [Employee]</span></div>
<div><span style="font-size: x-small;">GO</span></div>
<div><span style="font-size: x-small;">CREATE TABLE EmpDetails</span></div>
<div><span style="font-size: x-small;">(</span></div>
<div><span style="font-size: x-small;">empid int IDENTITY NOT NULL,</span></div>
<div><span style="font-size: x-small;">empname varchar(20),</span></div>
<div><span style="font-size: x-small;">empimg image</span></div>
<div><span style="font-size: x-small;">)</span></div>
<div><span style="font-size: x-small;"><span style="font-family: Verdana;"><strong>Step 1:</strong> Create a new asp.net website. In the code-behind, add the following namespace</span></span></div>
<div><span style="font-family: Verdana; font-size: x-small;">C#</span></div>
<div><span style="font-size: x-small;">using System.Data.SqlClient;</span></div>
<div><span style="font-family: Verdana; font-size: x-small;">VB.NET</span></div>
<div><span style="font-size: x-small;">Imports System.Data.SqlClient</span></div>
<div align="justify"><span style="font-size: x-small;"><span style="font-family: Verdana;"><strong>Step 2:</strong> Drag and drop two label and one textbox control. Also drag drop a FileUpload control and a button control to upload the selected image on button click. As mentioned earlier, there are no validations performed. The source would look similar to the following:</span></span></div>
<div><span style="font-size: x-small;">&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</span></div>
<div><span style="font-size: x-small;">&lt;head runat=&#8221;server&#8221;&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;title&gt;Save Retrieve Images&lt;/title&gt;</span></div>
<div><span style="font-size: x-small;">&lt;/head&gt;</span></div>
<div><span style="font-size: x-small;">&lt;body&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;div&gt;</span></div>
<div><span style="font-size: x-small;">    </span></div>
<div><span style="font-size: x-small;">        &lt;asp:Label ID=&#8221;lblEmpName&#8221; runat=&#8221;server&#8221; Text=&#8221;Employee Name&#8221;&gt;&lt;/asp:Label&gt;</span></div>
<div><span style="font-size: x-small;">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</span></div>
<div><span style="font-size: x-small;">        &lt;asp:TextBox ID=&#8221;txtEName&#8221; runat=&#8221;server&#8221;&gt;&lt;/asp:TextBox&gt;</span></div>
<div><span style="font-size: x-small;">        &lt;br /&gt;</span></div>
<div><span style="font-size: x-small;">        &lt;asp:Label ID=&#8221;lblImage&#8221; runat=&#8221;server&#8221; Text=&#8221;Employee Image&#8221;&gt;&lt;/asp:Label&gt;</span></div>
<div><span style="font-size: x-small;">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</span></div>
<div><span style="font-size: x-small;">        &lt;asp:FileUpload ID=&#8221;imgUpload&#8221; runat=&#8221;server&#8221; /&gt;</span></div>
<div><span style="font-size: x-small;">        &lt;br /&gt;</span></div>
<div><span style="font-size: x-small;">        &lt;br /&gt;</span></div>
<div><span style="font-size: x-small;">        &lt;asp:Button ID=&#8221;btnSubmit&#8221; runat=&#8221;server&#8221; onclick=&#8221;btnSubmit_Click&#8221; </span></div>
<div><span style="font-size: x-small;">            Text=&#8221;Submit&#8221; /&gt;</span></div>
<div><span style="font-size: x-small;">    </span></div>
<div><span style="font-size: x-small;">    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp</span><span style="font-size: x-small;">        &lt;asp:Label ID=&#8221;lblResult&#8221; runat=&#8221;server&#8221; ForeColor=&#8221;#0066FF&#8221;&gt;&lt;/asp:Label&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;br /&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;hr /&gt;</span></div>
<div><span style="font-size: x-small;">   </span></div>
<div><span style="font-size: x-small;">   &lt;asp:Image ID=&#8221;Image1&#8243; style=&#8221;width:200px&#8221; Runat=&#8221;server&#8221; /&gt;</span></div>
<div><span style="font-size: x-small;">    </span></div>
<div><span style="font-size: x-small;">    </span></div>
<div><span style="font-size: x-small;">    &lt;/div&gt;</span></div>
<div><span style="font-size: x-small;">    &lt;/form&gt;</span></div>
<div><span style="font-size: x-small;">&lt;/body&gt;</span></div>
<div><span style="font-size: x-small;">&lt;/html&gt;</span></div>
<div><span style="font-size: x-small;"><span style="font-family: Verdana;"><strong>Step 3:</strong> In the button click event, add the following code:</span></span></div>
<div><span style="font-size: x-small;"><span style="font-family: Verdana;"> C#</span></span></div>
<div><span style="font-size: x-small;">protected void btnSubmit_Click(object sender, EventArgs e)</span></div>
<div><span style="font-size: x-small;">    {</span></div>
<div><span style="font-size: x-small;">        SqlConnection connection = null;</span></div>
<div><span style="font-size: x-small;">        try</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            FileUpload img = (FileUpload)imgUpload;</span></div>
<div><span style="font-size: x-small;">            Byte[] imgByte = null;</span></div>
<div><span style="font-size: x-small;">            if (img.HasFile &amp;&amp; img.PostedFile != null)</span></div>
<div><span style="font-size: x-small;">            {</span></div>
<div><span style="font-size: x-small;">                //To create a PostedFile</span></div>
<div><span style="font-size: x-small;">                HttpPostedFile File = imgUpload.PostedFile;</span></div>
<div><span style="font-size: x-small;">                //Create byte Array with file len</span></div>
<div><span style="font-size: x-small;">                imgByte = new Byte[File.ContentLength];</span></div>
<div><span style="font-size: x-small;">                //force the control to load data in array</span></div>
<div><span style="font-size: x-small;">                File.InputStream.Read(imgByte, 0, File.ContentLength);</span></div>
<div><span style="font-size: x-small;">            }</span></div>
<div><span style="font-size: x-small;">            // Insert the employee name and image into db</span></div>
<div><span style="font-size: x-small;">string conn = ConfigurationManager.ConnectionStrings ["EmployeeConnString"].ConnectionString;</span></div>
<div><span style="font-size: x-small;">            connection = new SqlConnection(conn);</span></div>
<div><span style="font-size: x-small;">            connection.Open();</span></div>
<div><span style="font-size: x-small;">string sql = &#8220;INSERT INTO EmpDetails(empname,empimg) VALUES(@enm, @eimg) SELECT @@IDENTITY&#8221;;</span></div>
<div><span style="font-size: x-small;">            SqlCommand cmd = new SqlCommand(sql, connection);</span></div>
<div><span style="font-size: x-small;">            cmd.Parameters.AddWithValue(&#8220;@enm&#8221;, txtEName.Text.Trim());</span></div>
<div><span style="font-size: x-small;">            cmd.Parameters.AddWithValue(&#8220;@eimg&#8221;, imgByte);</span></div>
<div><span style="font-size: x-small;">            int id = Convert.ToInt32(cmd.ExecuteScalar());</span></div>
<div><span style="font-size: x-small;">            lblResult.Text = String.Format(&#8220;Employee ID is {0}&#8221;, id);</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">        catch</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            lblResult.Text = &#8220;There was an error&#8221;;</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">        finally</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            connection.Close();</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">    }</span></div>
<div><span style="font-family: Verdana; font-size: x-small;">VB.NET</span></div>
<div><span style="font-size: x-small;">Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click</span></div>
<div><span style="font-size: x-small;">        Dim connection As SqlConnection = Nothing</span></div>
<div><span style="font-size: x-small;">        Try</span></div>
<div><span style="font-size: x-small;">            Dim img As FileUpload = CType(imgUpload, FileUpload)</span></div>
<div><span style="font-size: x-small;">            Dim imgByte As Byte() = Nothing</span></div>
<div><span style="font-size: x-small;">            If img.HasFile AndAlso Not img.PostedFile Is Nothing Then</span></div>
<div><span style="font-size: x-small;">                &#8216;To create a PostedFile</span></div>
<div><span style="font-size: x-small;">                Dim File As HttpPostedFile = imgUpload.PostedFile</span></div>
<div><span style="font-size: x-small;">                &#8216;Create byte Array with file len</span></div>
<div><span style="font-size: x-small;">                imgByte = New Byte(File.ContentLength &#8211; 1) {}</span></div>
<div><span style="font-size: x-small;">                &#8216;force the control to load data in array</span></div>
<div><span style="font-size: x-small;">                File.InputStream.Read(imgByte, 0, File.ContentLength)</span></div>
<div><span style="font-size: x-small;">            End If</span></div>
<div><span style="font-size: x-small;">            &#8216; Insert the employee name and image into db</span></div>
<div><span style="font-size: x-small;">            Dim conn As String = ConfigurationManager.ConnectionStrings(&#8220;EmployeeConnString&#8221;).ConnectionString</span></div>
<div><span style="font-size: x-small;">            connection = New SqlConnection(conn)</span></div>
<div><span style="font-size: x-small;">            connection.Open()</span></div>
<div><span style="font-size: x-small;">            Dim sql As String = &#8220;INSERT INTO EmpDetails(empname,empimg) VALUES(@enm, @eimg) SELECT @@IDENTITY&#8221;</span></div>
<div><span style="font-size: x-small;">            Dim cmd As SqlCommand = New SqlCommand(sql, connection)</span></div>
<div><span style="font-size: x-small;">            cmd.Parameters.AddWithValue(&#8220;@enm&#8221;, txtEName.Text.Trim())</span></div>
<div><span style="font-size: x-small;">            cmd.Parameters.AddWithValue(&#8220;@eimg&#8221;, imgByte)</span></div>
<div><span style="font-size: x-small;">            Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())</span></div>
<div><span style="font-size: x-small;">            lblResult.Text = String.Format(&#8220;Employee ID is {0}&#8221;, id)</span></div>
<div><span style="font-size: x-small;">        Catch</span></div>
<div><span style="font-size: x-small;">            lblResult.Text = &#8220;There was an error&#8221;</span></div>
<div><span style="font-size: x-small;">        Finally</span></div>
<div><span style="font-size: x-small;">            connection.Close()</span></div>
<div><span style="font-size: x-small;">        End Try</span></div>
<div><span style="font-size: x-small;">    End Sub</span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">In the code above, we are creating a byte array equal to the length of the file. The byte array will store the image. We then load the image data into the array. The record containing the Employee Name and Image is then inserted into the database using the ADO.NET code. The ID inserted is returned back using the @@Identity. We will shortly use this ID and pass it as a query string parameter to the ShowImage handler. The image will then be fetched against the EmployeeID (empid).</span></div>
<div align="justify"><span style="font-size: x-small;"><span style="font-family: Verdana;"><strong>Step 4:</strong> In order to display the image on the page, we will create an Http handler. To do so, right click project &gt; Add New Item &gt; Generic Handler &gt; ShowImage.ashx. The code shown below, uses the Request.QueryString[“id”] to retrieve the EmployeeID from it. The ID is then passed to the ‘ShowEmpImage()’ method where the image is fetched from the database and returned in a MemoryStream object. We then read the stream into a byte array. Using the OutputStream.Write(), we write the sequence of bytes to the current stream and you get to see your image.</span></span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">C#</span></div>
<div><span style="font-size: x-small;">&lt;%@ WebHandler Language=&#8221;C#&#8221; Class=&#8221;ShowImage&#8221; %&gt;</span></div>
<div><span style="font-size: x-small;">using System;</span></div>
<div><span style="font-size: x-small;">using System.Configuration;</span></div>
<div><span style="font-size: x-small;">using System.Web;</span></div>
<div><span style="font-size: x-small;">using System.IO;</span></div>
<div><span style="font-size: x-small;">using System.Data;</span></div>
<div><span style="font-size: x-small;">using System.Data.SqlClient;</span></div>
<div><span style="font-size: x-small;">public class ShowImage : IHttpHandler </span></div>
<div><span style="font-size: x-small;">{</span></div>
<div><span style="font-size: x-small;">    public void ProcessRequest(HttpContext context)</span></div>
<div><span style="font-size: x-small;">    {</span></div>
<div><span style="font-size: x-small;">       Int32 empno;</span></div>
<div><span style="font-size: x-small;">       if (context.Request.QueryString["id"] != null)</span></div>
<div><span style="font-size: x-small;">            empno = Convert.ToInt32(context.Request.QueryString["id"]);</span></div>
<div><span style="font-size: x-small;">       else</span></div>
<div><span style="font-size: x-small;">            throw new ArgumentException(&#8220;No parameter specified&#8221;);</span></div>
<div><span style="font-size: x-small;">       context.Response.ContentType = &#8220;image/jpeg&#8221;;</span></div>
<div><span style="font-size: x-small;">       Stream strm = ShowEmpImage(empno);</span></div>
<div><span style="font-size: x-small;">       byte[] buffer = new byte[4096];</span></div>
<div><span style="font-size: x-small;">       int byteSeq = strm.Read(buffer, 0, 4096);</span></div>
<div><span style="font-size: x-small;">       while (byteSeq &gt; 0)</span></div>
<div><span style="font-size: x-small;">       {</span></div>
<div><span style="font-size: x-small;">           context.Response.OutputStream.Write(buffer, 0, byteSeq);</span></div>
<div><span style="font-size: x-small;">           byteSeq = strm.Read(buffer, 0, 4096);</span></div>
<div><span style="font-size: x-small;">       }        </span></div>
<div><span style="font-size: x-small;">       //context.Response.BinaryWrite(buffer);</span></div>
<div><span style="font-size: x-small;">    }</span></div>
<div><span style="font-size: x-small;">    public Stream ShowEmpImage(int empno)</span></div>
<div><span style="font-size: x-small;">    {</span></div>
<div><span style="font-size: x-small;"> string conn = ConfigurationManager.ConnectionStrings     ["EmployeeConnString"].ConnectionString;</span></div>
<div><span style="font-size: x-small;">        SqlConnection connection = new SqlConnection(conn);</span></div>
<div><span style="font-size: x-small;">        string sql = &#8220;SELECT empimg FROM EmpDetails WHERE empid = @ID&#8221;;</span></div>
<div><span style="font-size: x-small;">        SqlCommand cmd = new SqlCommand(sql,connection);</span></div>
<div><span style="font-size: x-small;">        cmd.CommandType = CommandType.Text;</span></div>
<div><span style="font-size: x-small;">        cmd.Parameters.AddWithValue(&#8220;@ID&#8221;, empno);</span></div>
<div><span style="font-size: x-small;">        connection.Open();</span></div>
<div><span style="font-size: x-small;">        object img = cmd.ExecuteScalar();</span></div>
<div><span style="font-size: x-small;">        try</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            return new MemoryStream((byte[])img);</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">        catch </span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            return null;</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">        finally</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            connection.Close();</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">    }</span></div>
<div><span style="font-size: x-small;">    public bool IsReusable</span></div>
<div><span style="font-size: x-small;">    {</span></div>
<div><span style="font-size: x-small;">        get</span></div>
<div><span style="font-size: x-small;">        {</span></div>
<div><span style="font-size: x-small;">            return false;</span></div>
<div><span style="font-size: x-small;">        }</span></div>
<div><span style="font-size: x-small;">    }</span></div>
<div><span style="font-size: x-small;">}</span></div>
<div><span style="font-family: Verdana; font-size: x-small;">VB.NET</span></div>
<div><span style="font-size: x-small;">&lt;%@ WebHandler Language=&#8221;vb&#8221; Class=&#8221;ShowImage&#8221; %&gt;</span></div>
<div><span style="font-size: x-small;">Imports System</span></div>
<div><span style="font-size: x-small;">Imports System.Configuration</span></div>
<div><span style="font-size: x-small;">Imports System.Web</span></div>
<div><span style="font-size: x-small;">Imports System.IO</span></div>
<div><span style="font-size: x-small;">Imports System.Data</span></div>
<div><span style="font-size: x-small;">Imports System.Data.SqlClient</span></div>
<div><span style="font-size: x-small;">Public Class ShowImage</span></div>
<div><span style="font-size: x-small;">    Implements IHttpHandler</span></div>
<div><span style="font-size: x-small;">    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest</span></div>
<div><span style="font-size: x-small;">        Dim empno As Int32</span></div>
<div><span style="font-size: x-small;">        If Not context.Request.QueryString(&#8220;id&#8221;) Is Nothing Then</span></div>
<div><span style="font-size: x-small;">            empno = Convert.ToInt32(context.Request.QueryString(&#8220;id&#8221;))</span></div>
<div><span style="font-size: x-small;">        Else</span></div>
<div><span style="font-size: x-small;">            Throw New ArgumentException(&#8220;No parameter specified&#8221;)</span></div>
<div><span style="font-size: x-small;">        End If</span></div>
<div><span style="font-size: x-small;">        context.Response.ContentType = &#8220;image/jpeg&#8221;</span></div>
<div><span style="font-size: x-small;">        Dim strm As Stream = ShowEmpImage(empno)</span></div>
<div><span style="font-size: x-small;">        Dim buffer As Byte() = New Byte(4095) {}</span></div>
<div><span style="font-size: x-small;">        Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)</span></div>
<div><span style="font-size: x-small;">        Do While byteSeq &gt; 0</span></div>
<div><span style="font-size: x-small;">            context.Response.OutputStream.Write(buffer, 0, byteSeq)</span></div>
<div><span style="font-size: x-small;">            byteSeq = strm.Read(buffer, 0, 4096)</span></div>
<div><span style="font-size: x-small;">        Loop</span></div>
<div><span style="font-size: x-small;">        &#8216;context.Response.BinaryWrite(buffer);</span></div>
<div><span style="font-size: x-small;">    End Sub</span></div>
<div><span style="font-size: x-small;">    Public Function ShowEmpImage(ByVal empno As Integer) As Stream</span></div>
<div><span style="font-size: x-small;">        Dim conn As String = ConfigurationManager.ConnectionStrings(&#8220;EmployeeConnString&#8221;).ConnectionString</span></div>
<div><span style="font-size: x-small;">        Dim connection As SqlConnection = New SqlConnection(conn)</span></div>
<div><span style="font-size: x-small;">        Dim sql As String = &#8220;SELECT empimg FROM EmpDetails WHERE empid = @ID&#8221;</span></div>
<div><span style="font-size: x-small;">        Dim cmd As SqlCommand = New SqlCommand(sql, connection)</span></div>
<div><span style="font-size: x-small;">        cmd.CommandType = CommandType.Text</span></div>
<div><span style="font-size: x-small;">        cmd.Parameters.AddWithValue(&#8220;@ID&#8221;, empno)</span></div>
<div><span style="font-size: x-small;">        connection.Open()</span></div>
<div><span style="font-size: x-small;">        Dim img As Object = cmd.ExecuteScalar()</span></div>
<div><span style="font-size: x-small;">        Try</span></div>
<div><span style="font-size: x-small;">            Return New MemoryStream(CType(img, Byte()))</span></div>
<div><span style="font-size: x-small;">        Catch</span></div>
<div><span style="font-size: x-small;">            Return Nothing</span></div>
<div><span style="font-size: x-small;">        Finally</span></div>
<div><span style="font-size: x-small;">            connection.Close()</span></div>
<div><span style="font-size: x-small;">        End Try</span></div>
<div><span style="font-size: x-small;">    End Function</span></div>
<div><span style="font-size: x-small;">    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable</span></div>
<div><span style="font-size: x-small;">        Get</span></div>
<div><span style="font-size: x-small;">            Return False</span></div>
<div><span style="font-size: x-small;">        End Get</span></div>
<div><span style="font-size: x-small;">    End Property</span></div>
<div><span style="font-size: x-small;">End Class</span></div>
<div align="justify"><span style="font-size: x-small;"><span style="font-family: Verdana;"><strong>Step 5:</strong> One final step. Add the following code in the button click (just above the catch block) to call the handler and display the newly inserted image from the database. In the code below, we pass the EmployeeID as a query string parameter to the Http Handler.</span></span></div>
<div><span style="font-family: Verdana; font-size: x-small;">C#</span></div>
<div><span style="font-size: x-small;">// Display the image from the database</span></div>
<div><span style="font-size: x-small;">Image1.ImageUrl = &#8220;~/ShowImage.ashx?id=&#8221; + id;</span></div>
<div><span style="font-family: Verdana; font-size: x-small;">VB.NET</span></div>
<div><span style="font-size: x-small;">&#8216; Display the image from the database</span></div>
<div><span style="font-size: x-small;"> Image1.ImageUrl = &#8220;~/ShowImage.ashx?id=&#8221; &amp; id</span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">That’s it. Run the code and check out the functionality. Just change the connection string in the web.config to point to your database. The code works fine for .jpg, .gif and .bmp images. I would encourage you to extend the sample and include validations in it. Some validations could be to check the size of the image uploaded, make sure that only images are uploaded, check the length of the Employee name, prevent the user from entering numeric and special characters, so on and so forth. </span></div>
<div align="justify"><span style="font-size: x-small;"><span style="font-family: Verdana;">The <strong>source code</strong> of this article, both in C# and VB.NET, can be downloaded from <a href="http://cid-2c5f5b0560e374cb.skydrive.live.com/self.aspx/.Public/Uploads/ReadWriteImages.zip"><strong>here</strong></a>.</span></span></div>
<div align="justify"><span style="font-family: Verdana; font-size: x-small;">I hope this article was useful and I thank you for viewing it. </span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/save-and-retrieve-images-from-the-database-using-asp-net-2-0-and-asp-net-3-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Music and Me</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-music-and-me/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-music-and-me/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 22:23:08 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=594</guid>
		<description><![CDATA[We&#8217;ve been together for such a long time now Music, music and me Don&#8217;t care wether all our songs rhyme Now music, music and me Only know wherever I go We&#8217;re as close as two friends can be There have been others But never two lovers Like music, music and me Grab a song and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">We&#8217;ve been together for such a long time now<br />
Music, music and me<br />
Don&#8217;t care wether all our songs rhyme<br />
Now music, music and me</p>
<p style="text-align: center;">Only know wherever I go<br />
We&#8217;re as close as two friends can be<br />
There have been others<br />
But never two lovers<br />
Like music, music and me</p>
<p style="text-align: center;">Grab a song and come along<br />
You can sing your melody<br />
In your mind you will find<br />
A world of sweet harmony</p>
<p style="text-align: center;">Birds of a feather will fly together<br />
Now music, music and me<br />
Music and me</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-music-and-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Morning Glow</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-morning-glow/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-morning-glow/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 22:20:50 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=590</guid>
		<description><![CDATA[Morning glow, morning glow Starts to glimmer when you know Winds of change are set to blow And sweep this whole land through Morning glow is long past due Morning glow fill the earth Come on shine far all you&#8217;re worth We&#8217;ll be present at the birth Of all faith looking new Morning glow is [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Morning glow, morning glow<br />
Starts to glimmer when you know<br />
Winds of change are set to blow<br />
And sweep this whole land through<br />
Morning glow is long past due</p>
<p style="text-align: center;">Morning glow fill the earth<br />
Come on shine far all you&#8217;re worth<br />
We&#8217;ll be present at the birth<br />
Of all faith looking new<br />
Morning glow is long past due</p>
<p style="text-align: center;">Oh oh morning glow<br />
I&#8217;d like to help you grow<br />
You should have started long ago</p>
<p style="text-align: center;">Morning glow all days long<br />
For we sing tomorrow&#8217;s song<br />
Never knew we could be so strong<br />
But now it&#8217;s very clear<br />
Morning glow is almost here</p>
<p style="text-align: center;">Oh oh morning glow<br />
I&#8217;d like to help you grow<br />
We should have started long ago</p>
<p style="text-align: center;">Morning glow all of your life<br />
We can make the new day right<br />
All the bad songs of the night<br />
Will fade into the past<br />
Morning glow is here at last</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-morning-glow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Euphoria</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-euphoria/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-euphoria/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 22:18:35 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=586</guid>
		<description><![CDATA[Love, Love, Love,Love Love, Love, Love,Love Love, Love, Love,Love Love, Love, Love,Love Euphoria, Euphoria, Euphoria,Euphoria E-U-P-H-O-R-I-A That&#8217;s the new word for today E-U-P-H-O-R-I-A It&#8217;s very easy to say Say Euphoria and you&#8217;ll feel fine from the start You can close your eyes And see the world with your heart Do what you wish, be what [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Love, Love, Love,Love<br />
Love, Love, Love,Love<br />
Love, Love, Love,Love<br />
Love, Love, Love,Love<br />
Euphoria, Euphoria, Euphoria,Euphoria</p>
<p style="text-align: center;">E-U-P-H-O-R-I-A<br />
That&#8217;s the new word for today<br />
E-U-P-H-O-R-I-A<br />
It&#8217;s very easy to say<br />
Say Euphoria and you&#8217;ll feel fine from the start<br />
You can close your eyes<br />
And see the world with your heart<br />
Do what you wish, be what you are<br />
What a victorious thrill<br />
Wearing a smile, all of the while<br />
Feeling the world standing still<br />
Watch raindbows glow rest on a bed of flowers<br />
Then dial a star<br />
Anything&#8217;s in your powers</p>
<p style="text-align: center;">E-U-P-H-O-R-I-A<br />
Full euphoria<br />
Knowing no ills, needing no pills<br />
Singing a rock and roll hymn<br />
Feeling glorious, full of love<br />
Fine from the start<br />
You can close your eyes<br />
And see the world with your heart<br />
How good to be happy and free<br />
Living the way that you choose<br />
Healthly and clean<br />
Can&#8217;t understand anyone having the blues<br />
Euphoria never to feel frustration<br />
How great to give love without invitation<br />
Euphoria, euphoria<br />
Long as we love each other<br />
Euphoria, euphoria<br />
Living for one another<br />
Euphoria, euphoria<br />
That&#8217;s one word for heaven<br />
Euphoria, euphoria<br />
living your live as Heaven</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-euphoria/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Johnny Raven</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-johnny-raven/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-johnny-raven/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 22:16:13 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=582</guid>
		<description><![CDATA[Free and untamed that&#8217;s how I&#8217;ve grown (It&#8217;s Johnny Raven) Settling down ain&#8217;t my nature Roots I&#8217;ll never own (It&#8217;s Johnny Raven) Oh your smile But tell me, ain&#8217;t your child How can you cage a bird Born to be wild Refrain I&#8217;m Johnny Raven (He&#8217;s Johnny Raven) by and by (By and By) Oh, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Free and untamed that&#8217;s how I&#8217;ve grown<br />
(It&#8217;s Johnny Raven)<br />
Settling down ain&#8217;t my nature<br />
Roots I&#8217;ll never own<br />
(It&#8217;s Johnny Raven)<br />
Oh your smile<br />
But tell me, ain&#8217;t your child<br />
How can you cage a bird<br />
Born to be wild</p>
<p style="text-align: center;">Refrain<br />
I&#8217;m Johnny Raven<br />
(He&#8217;s Johnny Raven)<br />
by and by (By and By)<br />
Oh, I&#8217;m going to leave your nest girl<br />
Another nest to try<br />
Ooh Johnny Raven<br />
Girl you know I shouldn&#8217;t have loved you<br />
Yeah, but I gotta leave you<br />
When my restless heart says goodbye</p>
<p style="text-align: center;">Look at you little girl<br />
You feel love so deep<br />
(It&#8217;s Johnny Raven)<br />
If I could change in a second<br />
I&#8217;d change for you like that<br />
Stay right here for keeps<br />
(It&#8217;s Johnny Raven)<br />
But I&#8217;m home free for no thrills<br />
Stray I will<br />
Seems I gotta need one girl<br />
Never can feel</p>
<p style="text-align: center;">Refrain<br />
Yeah I&#8217;m Johnny Raven<br />
(It&#8217;s Johnny Raven)<br />
by and by<br />
Oh, I&#8217;m going to leave yoour nest girl<br />
Another nest to try<br />
Ooh Johnny Raven<br />
Girl you know I shouldn&#8217;t have loved you<br />
Yeah, but I gotta leave you<br />
When my restless heart says goodbye</p>
<p style="text-align: center;">Everybody knows my name<br />
I&#8217;m Johnny Raven<br />
(It&#8217;s Johnny Raven)<br />
yeah, yeah by abd by<br />
(It&#8217;s Johnny Raven)<br />
I&#8217;m gonna fly<br />
When you cry part of me&#8217;s gonna die</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-johnny-raven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Doggin&#8217; Around</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-doggin-around/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-doggin-around/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 22:13:41 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=578</guid>
		<description><![CDATA[You better stop Your doggin&#8217; around Yeah, yeah, yeah, yeah &#8216;Cause if you don&#8217;t stop I&#8217;m gonna have to put you down I can&#8217;t take it much longer My heart&#8217;s getting weak It&#8217;s not getting any stronger You keep me so upset My head&#8217;s in a whirl But if you wanna be, yeah Be my [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">You better stop<br />
Your doggin&#8217; around<br />
Yeah, yeah, yeah, yeah<br />
&#8216;Cause if you don&#8217;t stop<br />
I&#8217;m gonna have to put you down</p>
<p style="text-align: center;">I can&#8217;t take it much longer<br />
My heart&#8217;s getting weak<br />
It&#8217;s not getting any stronger<br />
You keep me so upset<br />
My head&#8217;s in a whirl<br />
But if you wanna be, yeah<br />
Be my girl</p>
<p style="text-align: center;">You better stop<br />
Your doggin&#8217; around<br />
You know what I&#8217;m talkin&#8217; about<br />
Yeah, yeah, yeah<br />
If you don&#8217;t stop<br />
I&#8217;m gonna have to put you down<br />
Baby, yes I do, yes I do<br />
Gonna, gonna put you down<br />
You&#8217;re doggin&#8217; me [repeat 7x]<br />
I&#8217;m gonna have to put you down Yeah</p>
<p style="text-align: center;">Yes you do, you&#8217;re doggin&#8217; me [repeat 3x]<br />
You better stop<br />
Your doggin&#8217; me around</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-doggin-around/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Too Young</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-too-young/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-too-young/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 21:40:52 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=574</guid>
		<description><![CDATA[They try to tell us we&#8217;re too young Too young to really be in love They say that love&#8217;s a word A word we&#8217;ve only heard But can&#8217;t begin to know the meaning of And yet we&#8217;re not too young to know This love will last though years may go And then someday they may [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">They try to tell us we&#8217;re too young<br />
Too young to really be in love</p>
<p style="text-align: center;">They say that love&#8217;s a word<br />
A word we&#8217;ve only heard<br />
But can&#8217;t begin to know the meaning of</p>
<p style="text-align: center;">And yet we&#8217;re not too young to know<br />
This love will last though years may go</p>
<p style="text-align: center;">And then someday they may recall<br />
We were not to young at all</p>
<p style="text-align: center;">They try to tell us we&#8217;re too young<br />
Too young to really be in love</p>
<p style="text-align: center;">And yet we&#8217;re not too young to know<br />
This love will last though years may go<br />
And then someday they may recall<br />
We were not to young at all</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-too-young/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Happy</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-happy/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-happy/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 21:38:38 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=571</guid>
		<description><![CDATA[Sadness had been close as my next of kin Then Happy came one day, chased my blues away My life began when Happy smiled Sweet, like candy to a child Stay here and love me just a while Let sadness see what Happy does Let Happy be where Sadness was Happy, that&#8217;s you You made [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Sadness had been close as my next of kin<br />
Then Happy came one day, chased my blues away<br />
My life began when Happy smiled<br />
Sweet, like candy to a child<br />
Stay here and love me just a while<br />
Let sadness see what Happy does<br />
Let Happy be where Sadness was</p>
<p style="text-align: center;">Happy, that&#8217;s you<br />
You made my life brand new<br />
Lost as a little lam was I, till you came in<br />
My life began when Happy smiled<br />
Sweet, like candy to a child<br />
Stay here and love me just a while<br />
Let sadness see what Happy does<br />
Let Happy be where Sadness was<br />
(Till now)</p>
<p style="text-align: center;">Where have I been?<br />
What lifetime was I in?<br />
Suspended between time and space<br />
Lonely until Happy came smiling up at me<br />
Sadness had no choice but to flee<br />
I said a prayer so silently<br />
Let Sadness see what Happy does<br />
Let Happy be where Sadness was<br />
Till now</p>
<p style="text-align: center;">Happy, yeah yeah<br />
Happy, oehoe happy</p>
<p style="text-align: center;">happy oh yeah Happy<br />
[fade out]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-happy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; All The Things You Are</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-all-the-things-you-are/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-all-the-things-you-are/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 21:36:14 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=566</guid>
		<description><![CDATA[You are the promised kiss of springtime That makes the lonely winter seem long You are the breathless hush of evening That trembles on the brink of a lovely song You are the angel glow that lights a star The dearest things I know are what you are Some day my happy arms will hold [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">You are the promised kiss of springtime<br />
That makes the lonely winter seem long<br />
You are the breathless hush of evening<br />
That trembles on the brink of a lovely song<br />
You are the angel glow that lights a star<br />
The dearest things I know are what you are<br />
Some day my happy arms will hold you<br />
And some day I&#8217;ll know that moment divine<br />
When all the things you are, are mine</p>
<p style="text-align: center;">You are the angel glow that lights a star<br />
The dearest things I know are what you are<br />
Some, some, some, some, day<br />
My happy arms will hold you<br />
And some day I&#8217;ll know that moment divine<br />
When all the things you are, are mine<br />
yeah yeah, all the things you are, are mine<br />
all the things you are, got to be mine<br />
Some day you are, are mine<br />
all the things you are, got to be mine<br />
all the things you are, got to be mine<br />
[fade out]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-all-the-things-you-are/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MICHAEL JACKSON LYRICS &#8211; Up Again</title>
		<link>http://www.lyricsal.com/michael-jackson-lyrics-up-again/</link>
		<comments>http://www.lyricsal.com/michael-jackson-lyrics-up-again/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 21:34:13 +0000</pubDate>
		<dc:creator>lyricsal</dc:creator>
				<category><![CDATA[Michael Jackson]]></category>

		<guid isPermaLink="false">http://www.lyricsal.com/?p=562</guid>
		<description><![CDATA[Into each life some rain falls Then comes the snow But after the snow The flowers will grow Girl when my life got stormy You stayed for the ride You stayed my side You make the sun shine [Refrain] I&#8217;m up again I never let you down Nothing&#8217;s ever gonna stop me now Up again [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Into each life some rain falls<br />
Then comes the snow<br />
But after the snow<br />
The flowers will grow<br />
Girl when my life got stormy<br />
You stayed for the ride<br />
You stayed my side<br />
You make the sun shine</p>
<p style="text-align: center;">[Refrain]<br />
I&#8217;m up again I never let you down<br />
Nothing&#8217;s ever gonna stop me now<br />
Up again I never let you down<br />
I love you</p>
<p style="text-align: center;">This Humpty Dumpty&#8217;s lucky<br />
He&#8217;s had his fall<br />
But after it all<br />
He brushed himself off<br />
Knowing how much you loved me<br />
I made one more try<br />
I reached for the sky<br />
And I made it this time</p>
<p style="text-align: center;">[Refrain]<br />
I&#8217;m up again I never let you down<br />
Nothing&#8217;s ever gonna stop me now<br />
Up again I never let you down<br />
I love you</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lyricsal.com/michael-jackson-lyrics-up-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

