Click here to Skip to main content
16,016,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to save image in database and reterive image and display in picture box by using C# and Back end MS ACCESS
Posted

Hi,

Go throw this link

http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=79870[^]

Total functionality is provided by the link.
Regards,
Vinay
 
Share this answer
 
Comments
itsureshuk 28-Mar-12 7:38am    
error on reteriving image from database and display in picture box.....Getting Error as "Parameter is Not Valid"
private void btnToPB_Click(object sender,EventArgs e)
{
RefreshDBConnection();
rowNumber=0;
pictureBox1.Image=ReadImageFromDB();
btnToPB.Text="view 1st 



private Image ReadImageFromDB()
{
Image FetchdImg;
if(rowNumber >=0)
{
byte[]FetchedImgBytes=(byte[]LocalDataTable.Rows[rowNumber]["Photo"];

MemoryStream stream=new MemoryStream(FetchedImgBytes);

FetchedImg=Image.FromStream(stream);

return FetchedImg;

else
{
MessageBox.Show("there are no image in the database yet.please reconnect od add some Image");
return null;
}
 
Share this answer
 
C#
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
       Con = new OleDbConnection(@constr);
       Con.Open();

       Com = new OleDbCommand();
       Com.Connection = Con;
 {
  Com.CommandText = "SELECT Picture FROM <pics> WHERE Patient_Id =" + val + ", Con)
 using (SqlDataReader reader = cmd.ExecuteReader())
{
  if (reader.Read())
{
   byte[] picbyte= reader["Picture"] as byte[] ?? null;

   if (picbyte!= null)
   {
       using (MemoryStream ms = new MemoryStream(picData))
       {
           // Load the image from the memory stream. How you do it depends
           // on whether you're using Windows Forms or WPF.
           // For Windows Forms you could write:
           System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
       }
         }
       }
     }
   }
 
Share this answer
 

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