Visual basic -Data Listview data by tables

0
    Dim sqlConString As String = "Server=localhost\TESTE;Database=tempTest;User Id=sa;Password=123"
            Try
                Using con = New SqlConnection(sqlConString)
                    con.Open()
                    Using cmd = con.CreateCommand
                '' Para filtrar 
                cmd.CommandText = "SELECT * FROM Clientes where NIF LIKE  '" + TextBox1.Text + "%'"
                cmd.CommandText = "select * from Clientes"
                Using reader = cmd.ExecuteReader
                    Dim counter As Int32 = 0
                    While reader.Read
                        ListView1.Items.Add(reader.GetString(reader.GetOrdinal("NIF")), counter)
                        counter = counter + 1
                        ListView1.Items.Add(reader.GetString(reader.GetOrdinal("Nome")), counter)
                        counter = counter + 1
                        ListView1.Items.Add(reader.GetString(reader.GetOrdinal("Telefone")), counter)
                        counter = counter + 1
                        ''MsgBox(reader.GetString(reader.GetOrdinal("NIF")))
                    End While
                End Using
            End Using
        End Using
    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try

I want you to be on each table of these link

    
asked by anonymous 09.04.2018 / 17:24

1 answer

0

Good afternoon, follow example of how you could do using the a DataGridView.

Dim sql = "SELECT IdTipoAlimento, NomeTipoAlimento, NomeAlimento, QtdProteina FROM muscle.tb_alimentos"
Dim dt As Object = DAL.AcessoBD.ExecutarComando(sql, CommandType.Text, Nothing, DAL.AcessoBD.TipoDeComando.ExecuteDataSet)

For intCount As Integer = dt.Tables(0).Rows.Count - 1 To 0 Step -1
     Me.grdAlimento.Rows.Add(dt.Tables(0).Rows(intCount)("IdTipoAlimento"), dt.Tables(0).Rows(intCount)("NomeAlimento"), dt.Tables(0).Rows(intCount)("NomeTipoAlimento"), dt.Tables(0).Rows(intCount)("QtdProteina"))
     intCount2 = intCount2 + 1
Next
    
18.04.2018 / 18:50