Add data from an access table in a listbox

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Add data from an access table in a listbox

 
0
  #1
Aug 11th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 136
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 14
babbu babbu is offline Offline
Junior Poster

Re: Add data from an access table in a listbox

 
-1
  #2
Aug 11th, 2009
lstData.items.add(datatable.rows("column name")(row).tostring)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Re: Add data from an access table in a listbox

 
0
  #3
Aug 12th, 2009
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!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,703
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 483
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Add data from an access table in a listbox

 
0
  #4
Aug 12th, 2009
Post #2 - Improper syntax. Rows collection of DataTable uses int index argument.
  1. ...
  2. colvalue=datatable.rows(0)("column_name")
  3. lstData.items.add(colvalue)
  4. ...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Re: Add data from an access table in a listbox

 
0
  #5
Aug 12th, 2009
Thanks again but what do i declare colValue as and datatable in order to get the expected output.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,703
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 483
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Add data from an access table in a listbox

 
0
  #6
Aug 12th, 2009
>Thanks again but what do i declare colValue as and datatable in order to get the expected output.
Answer is Object type.
  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
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Re: Add data from an access table in a listbox

 
0
  #7
Aug 12th, 2009
Yo if you got it adatapost you got it.thanks a lot this code proved success.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC