Nel

Nel

  • NA
  • 716
  • 1.1m

How to insert picture in access database from C# form

Feb 1 2012 3:54 AM

Hi,

I have an access database with one field of type OLE Object. I want to insert a picture and I have this code:
 byte[] imageData = ReadFile(textBox15.Text);
com.Parameters.AddWithValue("@Slikadog", imageData);
 byte[] ReadFile(string sPath)
  {
 
  byte[] data = null;
  FileInfo fInfo = new FileInfo(sPath);
  long numBytes = fInfo.Length;
  FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
  BinaryReader br = new BinaryReader(fStream);
  data = br.ReadBytes((int)numBytes);
  return data;
  }
  void GetImagesFromDatabase()
  {
  try
  {
 
  OleDbDataAdapter ADAP = new OleDbDataAdapter("Select Slikadog from Dogovor", conn);
  DataSet DS = new DataSet();
  ADAP.Fill(DS, "Dogovor");
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }
  }


but when I run the application, in the database Ole Object field (the image field) I get only "Long binary data"
I don't know whether this is the right way to insert picture from a file. Please help me.
Thank you in advance.

Answers (4)