943,617 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 901
  • VB.NET RSS
Dec 8th, 2008
0

Error connecting to MySql

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cutieann12 is offline Offline
7 posts
since Nov 2008
Dec 8th, 2008
0

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.
VB.NET Syntax (Toggle Plain Text)
  1. 'start query
  2. ' Declare a DataSet object
  3. Dim Images As New DataSet()
  4.  
  5. myAdapter.Fill(Images, "Eyes")
  6. ' With DataAdapter you can close connection, with DataReader you have to keep connection open and close it at the end
  7. conn.Close()
  8.  
  9. ' Buffer to hold image data
  10. Dim ByteArr() As Byte
  11. Dim ImageIndex As Integer
  12. Dim i As Integer
  13.  
  14. ImageIndex = 0 ' Column index of images, set the right value in here
  15.  
  16. ' Loop all rows
  17. For i = 0 To Images.Tables(0).Rows.Count - 1
  18. ' Read a BLOB to buffer
  19. ByteArr = CType(Images.Tables(0).Rows.Item(i).Item(ImageIndex), Byte())
  20. ' Create a memory stream of the buffer
  21. Dim ImageStream As New MemoryStream(ByteArr)
  22. ' Get the image from the memory stream
  23. PictureBox1.Image = Image.FromStream(ImageStream)
  24. ' "Refresh" display
  25. Application.DoEvents()
  26. ' Wait 3 seconds
  27. System.Threading.Thread.Sleep(3000)
  28. Next i
You also have to import System.IO namespace to use memory stream.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Dec 11th, 2008
0

Re: Error connecting to MySql

Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Dec 11th, 2008
0

Re: Error connecting to MySql

Click to Expand / Collapse  Quote originally posted by tuse ...
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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cutieann12 is offline Offline
7 posts
since Nov 2008
Dec 11th, 2008
0

Re: Error connecting to MySql

try this connection string-

VB.NET Syntax (Toggle Plain Text)
  1. Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Teach Me a Comeback to Visual Basic.net Programming
Next Thread in VB.NET Forum Timeline: Is it worth getting Visual Basic Professional Edition?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC