C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to get Image from database to ASP.Net page


Posted Date: 15 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: shakti singh tanwarMember Level: Diamond    
Rating: Points: 10



The following code shows how to get Image from database to ASP.Net page.

For this particular code to work you should have an Image control and a Placeholder control on your page.


OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\shaktisingh.tanwar\Desktop\Image.mdb");
OleDbCommand cmd = new OleDbCommand("select * from ImageDb", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds);
byte[] bt = (byte[])ds.Tables[0].Rows[1]["Content"];

MemoryStream mem = new System.IO.MemoryStream(bt);

System.Drawing.Image img = System.Drawing.Image.FromStream(mem);
img.Save(Server.MapPath("test2.jpg"));
//Session["abc"] = "12";
//int ctr=0;
//foreach (System.Collections.Specialized.NameObjectCollectionBase.KeysCollection obj in Session.Keys)
// obj.Get(ctr);
mem.Close();
Image1.ImageUrl ="~/test2.jpg";
PlaceHolder1.Controls.Add(Image1);




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Image from database  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to use Hash Table in .Net
Previous Resource: How to populate a CheckedListbox control using data from database
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use