Getting an Exception! Any Help

I am running the following code to pull an image from my SQL Database. The image is a pointer to a file in a directory. I get the following exception "Conversion from type "DBNull" to type "String" is not valid. The highlighted line is where it throws the exception. Any help would greatly appreciated. Thanks.

Dim MyReader As OleDb.OleDbDataReader

Dim MyCommand As New OleDb.OleDbCommand("SELECT Name, Image FROM dbo.Info")

Dim MyConnection As New OleDb.OleDbConnection("Provider=SQLOLEDB;server=(local)\SQLExpress;Integrated Security=SSPI;database=dbOne")

MyConnection.Open()

MyCommand.Connection = MyConnection

MyReader = MyCommand.ExecuteReader

MyReader.Read()

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

MyConnection.Close()



Answer this question

Getting an Exception! Any Help

  • Dave Sundell

    You have to convert the binary data to a memory stream and then create a bitmap. There is an example on the vb-tips website.


  • beatriz_da

    I am having all sorts of trouble trying to modify this to get it to work. Everything I try causes issues. Is there an easier way or do I just need to tinker until I get it to work
  • Getting an Exception! Any Help