Cordial greeting colleagues, It turns out that I have a database called quote, a form in MS Visual Basic with a listbox and a button called consult. what I want to do is, by means of the consult button, show in the listbox the information that is in the database. To connect the application with my database use the following code in a module, creating the following function:
Imports MySql.Data.MySqlClient
Module conexion
'En este bloque esta el metodo o funcion para conectar con la base de datos
Public Function conectar()
Try
Dim conexion As New MySqlConnectionStringBuilder()
conexion.Server = "localhost"
conexion.UserID = "root"
conexion.Password = ""
conexion.Database = "cotizacion"
Dim con As New MySqlConnection(conexion.ToString())
con.Open()
MsgBox("La conexion se realizo correctamente", 64)
Catch ex As Exception
MsgBox("No se pudo conectar", 48)
End Try
Return 0
End Function
It perfectly connects with the function created, the function calls it in the form load.
Try to make the query, and show it in the listbox by means of the button in the following way:
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conectar()
End Sub
Private Sub btnconsultar_Click(sender As Object, e As EventArgs) Handles btnconsultar.Click
Dim sql As String = " SELECT nombre_estudio FROM estudios'"
Dim comando As New MySqlCommand(sql)
Dim resultado As MySqlDataReader
resultado = comando.ExecuteReader
listestudios.Items.Add(resultado)
End Sub
End Class
But I get an error, how could I do it correctly?