Question why my result is this???

gouki2005

New member
Joined
Oct 6, 2008
Messages
3
Programming Experience
Beginner
this mi CLASS function
VB.NET:
Expand Collapse Copy
  Public Function getlista() As ArrayList

        Dim milista As New ArrayList
        Dim conexion As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\am103208_avicultura.mdb;Persist Security Info=False")
        conexion.Open()
        Dim comando As New OleDb.OleDbCommand
        comando.CommandText = String.Format("Select id,tipoave,peso,edad from aves")
        comando.Connection = conexion
        Dim lector As OleDb.OleDbDataReader
        lector = comando.ExecuteReader

        While lector.Read
            Dim otrabajadores As New getsetaves
            otrabajadores.setid(lector(0))
            otrabajadores.settipoave(lector(1))
            otrabajadores.setpeso(lector(2))
            otrabajadores.setedad(lector(3))

            milista.Add(otrabajadores)


        End While


        Return milista



    End Function

This my button to fill a listbox

VB.NET:
Expand Collapse Copy
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.ListBox1.Items.Count > 0 Then
            Me.ListBox1.Items.Clear()
        End If
        Dim otrab As New aves.mantenimientoaves
        Dim listado As New ArrayList
        listado = otrab.getlista
        Dim trabaja As aves.getsetaves
        For Each trabaja In listado
            Me.ListBox1.Items.Add(trabaja)

        Next



    End Sub

the things is the listbox1 result is this


aves.getsetaves
aves.getsetaves
aves.getsetaves
aves.getsetaves

is the number of rows from my database it suppose to return ID and tipoave

:mad:
 
Found the solution BUT I dont understand????

I just Add this function

VB.NET:
Expand Collapse Copy
 Overrides Function tostring() As String
        Return getid() & "-" & gettipoave() & "-" & getpeso()
    End Function

the listbox IS showing that data from my database..BUT I Not using this function in the button if you check my first post...so I dont undesrtand why ??? :eek:
 
Yes, it uses the default ToString method of Object if the class don't supply a better ToString method, the default ToString method for classes just return the "namespace.classname" string.
 
Yes, it uses the default ToString method of Object if the class don't supply a better ToString method, the default ToString method for classes just return the "namespace.classname" string.

So for that reason every class in .NET have the Tostring function to show the real data to the user no just the name of the object ???
 
For reasons Object type has defined a ToString method, this is the base type for all types, so it is always valid to call ToString no matter what object. Whether the method should return anything useful is up to the class implementer to decide. In this case you have a reason to override and return a friendlier string for display purposes. You asked earlier "I Not using this function in the button?", the answer is the Listbox simply calls ToString on any object in its list when it draws the items.
 
You'd do far better to follow the tutorials given in the DW2 link in my signature, and learn how to do your data access the easy way.. :) Start with Creating a Simple Data App
 
Back
Top