Displaying an image stored as a pointer in a SQL table.

I am having trouble getting images to display on an application I am trying to build. I have my images stored in a directory and then have a pointer in sql to those files. I want to display the photo associated with the particular record in my windows form but I cannot seem to make it happen. Any advice or code samples would be appreciated. Thanks.

Answer this question

Displaying an image stored as a pointer in a SQL table.

  • Rimoldi

    Displaying the image. Yes, the "pointer" is a filename/path to the image. I tried doing it through a PictureBox but that has issues and tried through a DataGridViewer and that caused even greater issues. What I am going for is displaying the image with the rest of the data for a particular record but I don't really want it in a datagrid type view either, I would prefer it be in a view similar to a picture box or as a thumbnail. Thanks for any help.
  • Judoshiai

    I changed it to match my data but I cannot get VB to run it.  Here is what I put.

     Dim MyReader As OleDb.OleDbDataReader

    Dim MyCommand As New OleDB.OleDbCommand("SELECT Image FROM DataInfo")

    MyReader = MyCommand.ExecuteReader

    MyReader.Read()

    Me.PictureBox1.ImageLocation = Image.FromFile(MyReader("Image"))

    It tells me that a Declaration is needed for MyReader and that there is a syntax error for Me.  I have tried several different things but none seem to correct it.


  • Aditi A.Kirkole

    Scratch that. I actually got the code to go through with no errors but I still don't get anything represented in my PictureBox. I will keep trying some things. If you have any ideas why it might not show please let me know.
  • Nick Bowling

    Are you having trouble reading the database, or opening an image file

    (I presume your 'pointer' is actually a filename/path to the image).



  • iStalker

    I almost have this going but I have one issue. When I put "Image" after MyReader which is the column name where the images are it tells me that "Value of type 'System.Drawing.Image' cannot be converted to 'String'" and if I take the quotes off of Image it tells me Image is a type and cannot be used as an expression. So close...any help
  • John McPherson

    That's why I said it was "PSEUDO" code...

    1. The command object will need the connection object assigned

    2. The connection object will need the connection string assigned

    3. The connection will have to be opened prior to executing the command

    4. After you have retrieved the field info be sure to close the connection

    Dim MyReader As OleDb.OleDbDataReader

    Dim MyCommand As New OleDB.OleDbCommand("SELECT Image FROM DataInfo")

    Dim MyCOnnection as New OledbConnection(TheConnectionString)

    MyCommand.Connection = MyConnection

    MyConnection.Open

    MyReader = MyCommand.ExecuteReader

    MyReader.Read()

    Me.PictureBox1.ImageLocation = Image.FromFile(MyReader("Image"))

    MyCOnnection.close()



  • Vignesh Kannappan

    pseudo code:

    Dim MyReader As OleDbDataReader

    Dim MyCommand As New OleDbCommand("Select ImagePathField From MyTable")

    MyReader = MyCommand.ExecuteReader

    MyReader.Read()

    Me.PictureBox1.ImageLocation = MyReader("ImagePathField")

    or

    Me.PictureBox1.Image = Image.FromFile(MyReader("ImagePathField"))



  • Displaying an image stored as a pointer in a SQL table.