C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

retrrieve images from database to Imagebutton in C#.NEt


Posted Date: 27 Jul 2008      Posted By: Kumar      Member Level: Gold     Points: 1   Responses: 2



hi all,
i inserted the image to sqlserver 2005 database.i need to retrieve the image an d shown it in ImageButton in C#.NET .i have a problem while retrieve in imagebutton .
anyone please send me the correct code in C# Webapplication to retrieve the images and shown it in Image button /


Thanx in advance

kumar





Responses

Author: Gaddamchandrakanth    27 Jul 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

Hi

to retrieve the image from the database use the following code.

MemoryStream stream = new MemoryStream ();
SqlConnection connection = new
SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
try
{
connection.Open ();
SqlCommand command = new
SqlCommand ("select Picture from Image", connection);
byte[] image = (byte[]) command.ExecuteScalar ();
stream.Write (image, 0, image.Length);
Bitmap bitmap = new Bitmap (stream);
Response.ContentType = "image/gif";
bitmap.Save (Response.OutputStream, ImageFormat.Gif);
}
finally
{
connection.Close ();
stream.Close ();
}


Thanks and Regards
Chandrakanth



Author: Gaddamchandrakanth    27 Jul 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

Hi

to retrieve the image from the database use the following code.

MemoryStream stream = new MemoryStream ();
SqlConnection connection = new
SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
try
{
connection.Open ();
SqlCommand command = new
SqlCommand ("select Picture from Image", connection);
byte[] image = (byte[]) command.ExecuteScalar ();
stream.Write (image, 0, image.Length);
Bitmap bitmap = new Bitmap (stream);
Response.ContentType = "image/gif";
bitmap.Save (Response.OutputStream, ImageFormat.Gif);
}
finally
{
connection.Close ();
stream.Close ();
}


Thanks and Regards
Chandrakanth



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : advanced video clip in asp.net...plz help me...
Previous : Error in sending mail
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use