Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. MysqlConn = New MySqlConnection()
  2.  
  3. ' Define the SQL to grab data from table.
  4. SQL = "SELECT * FROM stock"
  5.  
  6. 'Connection String
  7. MysqlConn.ConnectionString = "server=teamva.000webhostapp.com;" _
  8. & "user id=XXXXXXXX;" _
  9. & "password=XXXXXX;" _
  10. & "database=db_name"
  11.  
  12. ' Try, Catch, Finally
  13. Try
  14. MysqlConn.Open()
  15.  
  16. ContactsCommand.Connection = MysqlConn
  17. ContactsCommand.CommandText = SQL
  18.  
  19. ContactsAdapter.SelectCommand = ContactsCommand
  20. ContactsAdapter.Fill(ContactsData)
  21.  
  22. DataGridView1.DataSource = ContactsData
  23.  
  24. Catch myerror As MySqlException
  25. MessageBox.Show("Cannot connect to database: " & myerror.Message)
  26. Finally
  27. MysqlConn.Close()
  28. MysqlConn.Dispose()
  29. End Try
  30.  
  31. Dim connStr As String = "server=localhost;user=id2653259_rickyuzuriha;database=id2653259_stock;password=******;"
  32. Dim conn As New MySqlConnection(connStr)
  33. Try
  34. Console.WriteLine("Connecting to MySQL...")
  35. conn.Open()
  36. 'do your queries'
  37. Catch ex As Exception
  38. Console.WriteLine(ex.ToString())
  39. Finally
  40. conn.Close()
  41. Console.WriteLine("Done.")
  42. End Try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement