Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.9k

Save and retrieve Image c#

Dec 4 2018 3:36 AM
I have app, but have some simple solution.
 
 Using this code to insert into sql and working fine.
But  i have 2000 employes and have problem with database was too big when put inside pictures of all workers
 
I need some help or solution, to save some loaction with file name exmp. c:\some folder\imageofemployee.jpg
 
When click on datagrid row (selection changed) to show picture from that location
 
Not put in sql image, just file location.
 
Some help???
 
I hope to good explane
  1. //Insert into sql  
  2.   
  3.  byte[] img_arr = null;  
  4.             MemoryStream ms = new MemoryStream();  
  5.             //dataPictureBox.Image.Save(ms, dataPictureBox.Image.RawFormat);  
  6.   
  7.             bool isNullOrEmpty = pictureBox1 == null || pictureBox1.Image == null;  
  8.             if (!isNullOrEmpty)  
  9.                 pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
  10.             img_arr = ms.GetBuffer();
  11.                     using (SqlConnection openCon = new SqlConnection(cs))  
  12.                     {  
  13.                         string saveStaff = "declare @maxNo integer = 0 select @maxNo = isnull(max(redni_broj), 0) from [dbo].[radnici]; Set @maxNo=@maxNo+1;  INSERT INTO dbo.radnici (redni_broj, data) VALUES (@maxNo,@data)";  
  14.   
  15.                         using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))  
  16.                         {  
  17.                             querySaveStaff.Connection = openCon;  
  18.                              
  19.                             querySaveStaff.Parameters.AddWithValue("@data", img_arr);
  20.                             openCon.Open();  
  21.                             querySaveStaff.ExecuteNonQuery();  
  22.                             openCon.Close();
  23.                         }

Answers (1)