user2447290
user2447290

Reputation:

How can dataset on MYSQL - VB.net?

I'm trying to save the query with DataSet()
As you can see in the part where it says: '

here dataset i dont know how it

That should be what I need is something in OleDB

con.Open()
adaptadordatos.Fill(conjuntoDatos, "Alumnos")
con.Close()

But I am using MYSQL vb.net 2010 I do not find much documentation about. I could use a good guide to good mysql - vb.net

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            Dim Conexion As New MySql.Data.MySqlClient.MySqlConnection
            Dim CadenaSQL As String = "SELECT * FROM Alumnos ORDER BY nombre"
            Dim CadenaConexion As String = "Data Source=localhost;" & _
                                           "Database=" & "NuevaBD" & ";" & _
                                           "User Id=root;Password="
            Dim Comando As New MySql.Data.MySqlClient.MySqlCommand(CadenaSQL)
            Conexion = New MySql.Data.MySqlClient.MySqlConnection(CadenaConexion)

            Try
                Dim conjuntoDatos As New DataSet()
            Conexion.Open()
            'here dataset i dont know how it
            'Comando.Fill(conjuntoDatos, "Alumnos")
            Conexion.Close()

            Dim tabla As DataTable
            tabla = conjuntoDatos.Tables("Alumnos")
            Dim fila As DataRow
            Me.ListaAlumnos.Items.Clear()
            For Each fila In tabla.Rows
                ' Muestra los datos en un ListBox
                Me.ListaAlumnos.Items.Add(fila.Item("Nombre") & " " & fila.Item("Apellidos"))
            Next
        Catch ex As MySql.Data.MySqlClient.MySqlException
            MsgBox("No se ha podido establecer " & vbCrLf & _
                      "la conexión con la base de datos.", MsgBoxStyle.Critical)
        Finally

            Select Case Conexion.State
                Case ConnectionState.Open
                    Conexion.Close()
            End Select
        End Try
    End Sub

Upvotes: 0

Views: 3495

Answers (1)

David
David

Reputation: 218887

Fill() is a method on a Data Adapter, not a Command. Even with the language barrier, that seems pretty heavily implied here:

adaptadordatos.Fill(conjuntoDatos, "Alumnos")

So create a data adapter...

Dim myAdapter As MySqlDataAdapter = New MySqlDataAdapter(CadenaSQL, Conexion)
myAdapter.Fill(conjuntoDatos, "Alumnos")

Upvotes: 0

Related Questions