Click here to Skip to main content
12,251,332 members (52,848 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP SQL-Server
Hi friends

Is there any possible to store the images in sql server data base.

Thank U.
Posted 11-Jul-12 2:53am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Espen Harlinn 11-Jul-12 9:18am
   
5'ed!
Mehdi Gholam 11-Jul-12 9:27am
   
Cheers Espen!
Manas Bhardwaj 11-Jul-12 9:31am
   
Correct +5!
Mehdi Gholam 11-Jul-12 9:41am
   
Thanks Manas!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Does google stops working?

Try search on google[^] first.

You can also try search on CodeProject Articles[^] or CodeProject QA[^]

This is simple code snippets which stores image in SQL using FileUpload control
FileStream file = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            BinaryReader str1 = new BinaryReader(file);
            byte[] bit = str1.ReadBytes(Convert.ToInt32( file.Length));
            SqlConnection connection = new SqlConnection("server=(local);database=test;integrated security=true");
            connection.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@Photo",bit);
            command.CommandText = "INSERT INTO image1(pic) VALUES (@Photo)";
            command.ExecuteNonQuery();
            connection.Close();
  Permalink  
Comments
Mehdi Gholam 11-Jul-12 9:27am
   
5'ed
Prasad_Kulkarni 11-Jul-12 23:51pm
   
Thank you Mehdi!
Manas Bhardwaj 11-Jul-12 9:31am
   
Correct +5!
Prasad_Kulkarni 11-Jul-12 23:51pm
   
Thank you Manas!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You want to store your image file in database o.k here you go:-
first take a FileUpload Control provide the Id of this control say fileUpload.
now take a button on button_Click write the following code:-

int length = fileUpload.PostedFile.ContentLength;
byte[] imgByte = new byte[length];
HttpPostedFile hpf = fileUpload.PostedFile;
hpf.InputStream.Read(imgByte, 0, length);


Now insert imgByte object into your database.
Remember datatype of your database column for Image must of type Image.
  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
Web01 | 2.8.160426.1 | Last Updated 11 Jul 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