Feeding codebehind list and displaying value in asp

1

I am first having deeper contact with an application in VB.NET. In case, I need to feed a list that I'm 'transforming into object' and later, display the same in my asp. I'm usually accustomed to working with C # in MVC and so I'm having serious difficulty here.

In my codebehind I have the methods:

Sub Main()
    Dim Pedidos = GetPedidos()
    DisplayList(Pedidos)
    Console.ReadLine()
End Sub

Sub DisplayList(ByVal Pedidos As IEnumerable(Of InformacoesPedido))
    For Each Pedido As InformacoesPedido In Pedidos
        Console.WriteLine("Nome do Agente: " & Pedido.Agente)
        Console.WriteLine()
    Next
End Sub

Function GetPedidos() As IEnumerable(Of InformacoesPedido)
    Dim MyConnectionCarrossel = New OleDbConnection(CONEXAO)
    MyConnectionCarrossel.Open()
    Dim ComandoCa As New OleDbCommand
    ComandoCa.Connection = MyConnectionCarrossel
    ComandoCa.CommandText = "SELECT * from tabela"
    Dim readerCa As OleDbDataReader = ComandoCa.ExecuteReader()

    Return New List(Of InformacoesPedido) From
        {
         New InformacoesPedido("Teste", "Teste 2", "Teste 3", "Teste 4", "Teste 5", "Teste 6")
        }

End Function

Public Class InformacoesPedido
    Public Property Agente As String
    Public Property Cliente As String
    Public Property Pedido As String
    Public Property Tipo As Integer
    Public Property Data As Integer
    Public Property ValorTotal As Integer

    Public Sub New()

    End Sub

    Public Sub New(ByVal AgenteNome As String,
                   ByVal ClienteNome As String,
                   ByVal PedidoNome As String,
                   ByVal TipoNome As Integer,
                   ByVal DataPedido As Integer,
                   ByVal ValorTotalPedido As Integer)

        Agente = AgenteNome
        Cliente = ClienteNome
        Pedido = PedidoNome
        Tipo = TipoNome
        Data = DataPedido
        ValorTotal = ValorTotalPedido
    End Sub
End Class

My idea was to feed my list as follows:

Return New List(Of InformacoesPedido) From
        {
    While readerCa.Read
         New InformacoesPedido(readerCa.Item("X"), readerCa.Item("Y"), readerCa.Item("Z"), readerCa.Item("A"), readerCa.Item("B"), readerCa.Item("C"))
    End While
        }

But I have seen that it is not possible. So how could I be feeding my list the basis of my query?

How can I call my function GetPedidos() in asp to display the results?

@EDIT

I was able to access my method as follows:

    <%For Each X In GetPedidos()%>
     <h2><%=X.Agente%></h2>
    <%Next%>

My biggest problem now is how to feed my list with query results

I removed the following method:

Sub DisplayList(ByVal Pedidos As IEnumerable(Of InformacoesPedido))
For Each Pedido As InformacoesPedido In Pedidos
    Console.WriteLine("Nome do Agente: " & Pedido.Agente)
    Console.WriteLine()
Next
End Sub
    
asked by anonymous 04.03.2015 / 15:35

1 answer

0

Resolved

Dim Valores = New List(Of ProdutosPedido)
While readerCa.Read
Valores.Add(New ProdutosPedido(readerCa.Item("X"), readerCa.Item("Y"), readerCa.Item("Z"), readerCa.Item("A"), readerCa.Item("B"), readerCa.Item("C")))
End While
    
06.03.2015 / 14:57