Advertisement
Guest User

Nietzsche

a guest
Mar 11th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Dim conexao As New MySqlConnection()
  2. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3. Dim sql As String
  4. Dim registos As MySqlDataReader
  5. conexao = New MySqlConnection
  6. conexao.ConnectionString = "SERVER=localhost; user=root; password=''; database=bd_escola"
  7. Try
  8. conexao.Open()
  9. Try
  10. sql = "SELECT modulos.moduloID FROM modulos"
  11. Dim comando As MySqlCommand = New MySqlCommand(sql, conexao)
  12. Try
  13. registos = comando.ExecuteReader
  14. While registos.Read
  15. modulo.Items.Add(registos("moduloID"))
  16. End While
  17.  
  18.  
  19. Finally
  20. conexao.Dispose()
  21. End Try
  22. Catch erro As MySqlException
  23. MessageBox.Show("Erro ao tentar ler a base de dados" & erro.Message)
  24. End Try
  25. Catch erro As MySqlException
  26. MessageBox.Show("Erro ao tentar ligar com o banco de dados", "atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
  27. Finally
  28. conexao.Dispose()
  29. End Try
  30.  
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement