943,678 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1301
  • VB.NET RSS
Aug 11th, 2009
0

Add data from an access table in a listbox

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008
Aug 11th, 2009
-1

Re: Add data from an access table in a listbox

lstData.items.add(datatable.rows("column name")(row).tostring)
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Aug 12th, 2009
0

Re: Add data from an access table in a listbox

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!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008
Aug 12th, 2009
0

Re: Add data from an access table in a listbox

Post #2 - Improper syntax. Rows collection of DataTable uses int index argument.
vb.net Syntax (Toggle Plain Text)
  1. ...
  2. colvalue=datatable.rows(0)("column_name")
  3. lstData.items.add(colvalue)
  4. ...
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Aug 12th, 2009
0

Re: Add data from an access table in a listbox

Thanks again but what do i declare colValue as and datatable in order to get the expected output.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008
Aug 12th, 2009
0

Re: Add data from an access table in a listbox

>Thanks again but what do i declare colValue as and datatable in order to get the expected output.
Answer is Object type.
vb.net Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim dt As New DataTable
  3. dt.Columns.Add("No", GetType(Int32))
  4. dt.Columns.Add("Name")
  5. dt.Rows.Add(1, "A")
  6. dt.Rows.Add(2, "B")
  7. dt.Rows.Add(3, "C")
  8.  
  9. For Each r As DataRow In dt.Rows
  10. ListBox1.Items.Add(r("No"))
  11. Next
  12. End Sub
Anothe code - DataSource bind
vb.net Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim dt As New DataTable
  3. dt.Columns.Add("No", GetType(Int32))
  4. dt.Columns.Add("Name")
  5.  
  6. dt.Rows.Add(1, "A")
  7. dt.Rows.Add(2, "B")
  8. dt.Rows.Add(3, "C")
  9.  
  10. ListBox1.DataSource = dt
  11. ListBox1.DisplayMember = "Name"
  12. ListBox1.ValueMember = "No"
  13. End Sub
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Aug 12th, 2009
0

Re: Add data from an access table in a listbox

Yo if you got it adatapost you got it.thanks a lot this code proved success.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: send sms to mobile phone
Next Thread in VB.NET Forum Timeline: Ned codes for VB Program about Bank System





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC