Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using C#, 2.0,sql server 2005 and visual studio 2005

Can anybody help with the following problem:

i have successfully uploaded image file into the database(where i have used image datatype).

now my problem is: How to retrieve that binary data (image file) from the table and insert it in another table(again store it as binary data).

please help me.
Thanks in Advance.
Updated 15-Jun-11 7:05am

All you need is a proper query to do the same.

Have a look at this article that retrives image and show in UI: C# Photo Album Viewer[^]

Share this answer
karan joshua 15-Jun-11 11:20am    
i tried but it is giving error.
Sandeep Mewara 15-Jun-11 11:43am    
What did you try and what was the error? We cannot assume or guess. :)
karan joshua 15-Jun-11 12:35pm    
i added following code:
<pre>public Stream SaveToMyDB()
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);


string strCmd = String.Format("SELECT ImageFile FROM MyImageTable WHERE ImgID ='"+ImgIDTextBox.Text+"'");
SqlCommand cmd = new SqlCommand(strCmd, connection);

byte[] b = (byte[])cmd.ExecuteScalar();
if(b.Length > 0)
// Open a stream for the image and write the bytes into it

System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(b, 0, b.Length);

// Create a bitmap from the stream

Bitmap bmp = new Bitmap(stream);

// Check for scaling and assign the bitmap to the Picturebox
return stream;



but it is giving error like:: not all code paths return a value .
karan joshua 15-Jun-11 13:55pm    
thank u very much.. it was 3 line code...But since i have used function and returned it it was giving problem,that was the problem. now i removed function. it is working fine now.thanks.
using array hold the binary data into variables and then send that array variables data to another table
Share this answer
karan joshua 15-Jun-11 11:04am    
how to do that?please help me..

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900