.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Store Images in Database using ASP.NET

Posted By:Athira Sreejith       Posted Date: December 31, 2008    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Here am explaining how to stores images in DataBase using ASP.NET.

Int64 intImageSize = default(Int64); 
string strImageType = null; 
Stream ImageStream = default(Stream); 
intImageSize = PersonImage.PostedFile.ContentLength; 
strImageType = PersonImage.PostedFile.ContentType; 
ImageStream = PersonImage.PostedFile.InputStream; 

byte[] ImageContent = new byte[intImageSize + 1]; 
int intStatus = 0; 
intStatus = ImageStream.Read(ImageContent, 0, intImageSize); 
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")); 
SqlCommand myCommand = new SqlCommand("sp_person", myConnection); 
myCommand.CommandType = CommandType.StoredProcedure; 
SqlParameter prmPersonImage = new SqlParameter("@Image", SqlDbType.Image); 
prmPersonImage.Value = ImageContent; 

SqlParameter prmPersonImageType = new SqlParameter("@ImageType", SqlDbType.VarChar, 255); 
prmPersonImageType.Value = strImageType; 
try { 
Response.Write("New person successfully added!"); 
catch (SqlException SQLexc) { 
Response.Write("Insert Failed. Error Details are: " + SQLexc.ToString()); 


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend