cuemasterfl
Supreme [H]ardness
- Joined
- Jul 5, 2001
- Messages
- 4,181
I'm trying to make my VB program connect to a MySQL database and retrieve some info from a query, and then have the result of that query show in a message box. I always get a 'blank' message box. I know the connection is being made, but obviously I'm doing something wrong. Any help would be appreciated. Thanks.
Edit: the database is on a remote server (not local)
Edit: the database is on a remote server (not local)
Code:
Dim MysqlConn As MySqlConnection
Dim SQLCommand As New MySqlCommand
Dim SQLAdapter As New MySqlDataAdapter
Dim SQLData As New DataTable
Dim SQL As String
MysqlConn = New MySqlConnection()
' Define the SQL to grab data from table.
SQL = "select * from users"
'Connection String
MysqlConn.ConnectionString = "server=xxx.xxx.xxx.xxx;" & "user id=xxxxx;" & "password=xxxxx;" & "database=xxxxx"
' Try, Catch, Finally
Try
MysqlConn.Open()
SQLCommand.Connection = MysqlConn
SQLCommand.CommandText = SQL
SQLAdapter.SelectCommand = SQLCommand
Dim result As String = SQLAdapter.Fill(SQLData)
MsgBox(result)
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
Finally
MysqlConn.Close()
MysqlConn.Dispose()
End Try