Hi guys please help with this i am trying to write my data from a table in a lis box but a always get the number of items inside the table. can some one come thru please.


lstData.items.Add(dataAdapter.fill(dataset,"MyTable")
all kinds of help will be appreciated

Recommended Answers

All 6 Replies

lstData.items.add(datatable.rows("column name")(row).tostring)

commented: Improper Syntax. -2

Thanks babbu for that piece of code and sorry for taking so long.The problem is i dont know how to declare data table explicitly so that i can treat it as one of my variables.That is why i am using dataset, cause i get not declared error.I can't figure out how to declare my table inside my code.Struggling thanx help please!!!

Post #2 - Improper syntax. Rows collection of DataTable uses int index argument.

...
   colvalue=datatable.rows(0)("column_name")
   lstData.items.add(colvalue) 
  ...

Thanks again but what do i declare colValue as and datatable in order to get the expected output.

>Thanks again but what do i declare colValue as and datatable in order to get the expected output.
Answer is Object type.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        dt.Columns.Add("No", GetType(Int32))
        dt.Columns.Add("Name")
        dt.Rows.Add(1, "A")
        dt.Rows.Add(2, "B")
        dt.Rows.Add(3, "C")
        
        For Each r As DataRow In dt.Rows
            ListBox1.Items.Add(r("No"))
        Next
    End Sub

Anothe code - DataSource bind

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        dt.Columns.Add("No", GetType(Int32))
        dt.Columns.Add("Name")

        dt.Rows.Add(1, "A")
        dt.Rows.Add(2, "B")
        dt.Rows.Add(3, "C")

        ListBox1.DataSource = dt
        ListBox1.DisplayMember = "Name"
        ListBox1.ValueMember = "No"
    End Sub

Yo if you got it adatapost you got it.thanks a lot this code proved success.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.