hello everyone, i need to make a program that will show/load the images stored in mysql database, i've already created the database and my problem is i can't load it in my vb code....

here's my code below

Dim conn As MySqlConnection
'connect to database
conn = New MySqlConnection()
conn.ConnectionString = "server = localhost; id = root; password = mypass; database=face manager"

Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database")
End Try

'sql query
Dim myAdapter As New MySqlDataAdapter

Dim sqlquery = "SELECT * FROM eyes"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery

'start query
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()

thanks, i need any response

For some reason I didn't get DataReader to work. But with DataAdapter and DataSet I got images from DB. I used SQL Server but that shouldn't make any difference.

'start query
' Declare a DataSet object
Dim Images As New DataSet()

myAdapter.Fill(Images, "Eyes")
' With DataAdapter you can close connection, with DataReader you have to keep connection open and close it at the end
conn.Close()

' Buffer to hold image data
Dim ByteArr() As Byte
Dim ImageIndex As Integer
Dim i As Integer

ImageIndex = 0 ' Column index of images, set the right value in here

' Loop all rows
For i = 0 To Images.Tables(0).Rows.Count - 1
  ' Read a BLOB to buffer
  ByteArr = CType(Images.Tables(0).Rows.Item(i).Item(ImageIndex), Byte())
  ' Create a memory stream of the buffer
  Dim ImageStream As New MemoryStream(ByteArr)
  ' Get the image from the memory stream
  PictureBox1.Image = Image.FromStream(ImageStream)
  ' "Refresh" display
  Application.DoEvents()
  ' Wait 3 seconds
  System.Threading.Thread.Sleep(3000)
Next i

You also have to import System.IO namespace to use memory stream.

Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?

Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?

Yes, i have installed MySql Connector Net version 1.0.10.1 and the connection string was correct..

try this connection string-

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
This article has been dead for over six months. Start a new discussion instead.