Click here to Skip to main content
14,736,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

What I have tried:

//Insert into sql  
 byte[] img_arr = null;  
            MemoryStream ms = new MemoryStream();  
            //dataPictureBox.Image.Save(ms, dataPictureBox.Image.RawFormat);  
            bool isNullOrEmpty = pictureBox1 == null || pictureBox1.Image == null;  
            if (!isNullOrEmpty)  
                pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);  
            img_arr = ms.GetBuffer();  
                    using (SqlConnection openCon = new SqlConnection(cs))  
                        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)";  
                        using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))  
                            querySaveStaff.Connection = openCon;  
                            querySaveStaff.Parameters.AddWithValue("@data", img_arr);  
Updated 4-Dec-18 5:40am
Richard MacCutchan 4-Dec-18 4:54am
Save the images in a folder somewhere that it can be accessed by your code. When you do the save, store the image in that folder and put its path location into the database.
Goran Bibic 4-Dec-18 5:06am
Yes. That. Need some code. Instruction...
Richard MacCutchan 4-Dec-18 5:12am
Construct the location where you will save the image; e.g. "C:\imagesaves\username\picture.jpg". Copy the image to that location, save the string in the database with its reference as key.
Goran Bibic 5-Dec-18 12:28pm
Some code? Or you can edit my code
Richard MacCutchan 5-Dec-18 13:01pm
I cannot explain it any more clearly. Try it yourself, it is not that difficult.
#realJSOP 4-Dec-18 10:09am
You can't write the code do do that?

1 solution

pictureBox1.Image.Save(@"D:\Temp\MyPic.jpg", ImageFormat.Jpeg);

Image.Save Method (System.Drawing) | Microsoft Docs[^]

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