DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Error connecting to MySql (http://www.daniweb.com/forums/thread161271.html)

cutieann12 Dec 8th, 2008 9:49 am
Error connecting to MySql
 
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

Teme64 Dec 8th, 2008 2:27 pm
Re: Error connecting to MySql
 
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.

tuse Dec 11th, 2008 7:21 am
Re: Error connecting to MySql
 
Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?

cutieann12 Dec 11th, 2008 10:49 am
Re: Error connecting to MySql
 
Quote:

Originally Posted by tuse (Post 754991)
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..

tuse Dec 11th, 2008 10:58 am
Re: Error connecting to MySql
 
try this connection string-

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;


All times are GMT -4. The time now is 10:00 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC