3
Answers

How to retrieve image form database

Sandeep Singh

Sandeep Singh

8y
242
1
Using this below code i am able to send my images to the database thru Linq to Sql
but i am unable to retrieve the images in PictureBox
 
  1. private void btnUpload_Click(object sender, EventArgs e)  
  2.         {  
  3.             openFileDialog1.FileName = "";  
  4.             openFileDialog1.Filter ="Jpeg Images(*.jpg)|*.jpg|Bitmap Images(*.bmp)|*.bmp|All Images(*.*)|*.*";  
  5.             DialogResult dr = openFileDialog1.ShowDialog();  
  6.             if (dr == DialogResult.OK)  
  7.             {  
  8.                 imgPath = openFileDialog1.FileName;  
  9.                 pictureBox1.ImageLocation = imgPath;  
  10.             }    
  11.         }  
 Insert into Database-->
  1. private void btnInsert_Click(object sender, EventArgs e)  
  2.        {  
  3.            int? Cid = null;  
  4.            if (imgPath.Trim().Length > 0)  
  5.            {  
  6.                byte[] data = File.ReadAllBytes(imgPath);  
  7.                Binary img = new Binary(data);  
  8.                dc.Customer_Insert(textBox2.Text, textBox3.Text, decimal.Parse(textBox4.Text), int.Parse(textBox5.Text),  
  9.                    img, ref Cid);  
  10.                textBox1.Text = Cid.ToString();  
  11.            }  
  12.            else  
  13.            {  
  14.                dc.Customer_Insert(textBox2.Text, textBox3.Text, decimal.Parse(textBox4.Text), int.Parse(textBox5.Text),  
  15.                                    nullref Cid);  
  16.                textBox1.Text = Cid.ToString();  
  17.            }  
  18.        }  
 
I want to display the image along with the whole information of Customer in my Window Application
 
 
 
 
Answers (3)