0

I am working on a Student Management System through windows form application. I need to store and retrieve student images to my database. I am getting an error

invalid parameter

every time I try to retrieve data from the SQL table. There might be error on the image storing procedure. Please help me out.

Here is my save and retrieve code:

Image img = Image.FromFile(ofd.FileName);
byte[] imageData;

using (MemoryStream ms = new MemoryStream())
{
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
    imageData = ms.ToArray();
}

and then I'm concatenating imageData to my sqlString.

And retrieving code:

byte[] arr = (byte[])dgv.Rows[e.RowIndex].Cells["memberImage"].Value;

MemoryStream str = new MemoryStream();
int offset = 78;
str.Write(arr, offset, arr.Length - offset);
Image img = Image.FromStream(str);
pbShowImage.Image = img;

This could be asked many time, but I'm getting a little frustrated on searching and implementing and getting again and again the same error

Onick Ahmed
  • 91
  • 1
  • 15
  • Which RDBMS is this for? Please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Jan 14 '17 at 12:24
  • 1
    Storing Images in your database is not a good practice. What you instead do is store images in your server and persist their paths in the database. And access them by their paths – Gayan Jan 14 '17 at 12:29
  • @Gayan After doing some head storming researching, now I'm thinking to switch my procedure. Now, I'm going to store them into my local folder that will store in my bin folder. I'll be end up with storing them on web server. i mean this software will run for a company in several pc through LAN. so than I've to sync my database. Can you suggest me that, is this a good way to doing this? *but there's something i found [link](http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay) thats a bit confusing. Please suggest anything helpful – Onick Ahmed Jan 15 '17 at 06:40

0 Answers0