Click here to Skip to main content
12,632,072 members (27,293 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET , +
hi,

How to insert image in database .

i am using ASP.NET,C#,SQL2005 and Microsoft Visual
Studio 2008.
Posted 13-May-12 21:22pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Inserting Image into database

1st Method: Store image in your server and pass the imageurl(stored image file path) to data base

2nd method :First Convert image into byte format then store into database(use the blob datatype in your table).
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You need to pass 'image in binary format' or 'folder location where image is stored' to your database using ADO.NET! Read about ADO.NET here and it will help you.

Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]


Following articles for reference, if needed:
Uploading and Storing Image Path to Database and Image to Folder - Part 1[^]
Uploading and Storing Image Path to Database and Image to Folder - Part 2[^]
Retrieving Image from SQL Database in C#[^]
  Permalink  
v2
Comments
Prasad_Kulkarni 14-May-12 5:37am
   
Surely a 5!
Sandeep Mewara 14-May-12 8:27am
   
Thanks Prasad.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3



 byte[] ImageBytes;
void ImageinBytes()
{
if (!string .IsNullOrEmpty ( FileName)) 
            {
                 Bitmap BitMap1 = new Bitmap(FileName);
                 System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
                BitMap1.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                ImageBytes = MemoryStream.ToArray();
            }
}



here FileName is complete path of File.



For extracting Bytes in Image again

void CovertingInImage()
        {
            System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream(ImageBytes);
            Bitmap BitMap2 = new Bitmap(MemoryStream);
            Image Image1;
            Image1 = Image.FromStream(MemoryStream);
        }


Here imagebytes is
  Permalink  
Comments
Prasad_Kulkarni 14-May-12 5:38am
   
Good answer +5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

I only move the image file to an folder, and save the image url in the database, to show the image, just go to the database fetch the url!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 16 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100