Solved

How to view data from a table with multiple rows

Posted on 2012-12-25
7
357 Views
Last Modified: 2012-12-28
I am using the code below to view countries in a table. How do I modify the code to use a next button to see all the countries in the table? The code below only displays the first record.

For Each xnDonor As Xml.XmlNode In xdDonor.SelectNodes("/Root/CountryTable[Country_ID='" & DonorID & "']")
                DonorID2 = xnDonor.SelectSingleNode("Country_ID").InnerText
                Name = xnDonor.SelectSingleNode("Country").InnerText
                dtDonor.Rows.Add({DonorID2, Name})
            Next
C1CountryOrigin.Text = dtDonor.Rows(0).Item("Country")
 
Thanks,

Victor
0
Comment
Question by:vcharles
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 38721000
I assume C1CountryOrigin is a label or textbox, so to list all the records you will need to convert the values to a string.
on the other hand, if you want to display them in a combobox, simply set its datasource to the datatable, e.g ComboBox1.DataSource = dtDonor (you may want to set the DisplayMember and the value Member if you choose this route).
In the same way, if you want to display the rows in a datagrid (or even datagridview), simply set its datasource to the datatable, e.g DataGridView1.DataSource = dtDonor (in this case the columns will be autogenerated from the datatable)
0
 

Author Comment

by:vcharles
ID: 38721010
Hi,

C1CountryOrigin  is a textbox, I need to see the data in the next row when I click on a Next button. What code do I use to see data in each fow?
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 38721015
declare a class wide integer variable as
Dim MyRowIndex As Integer = 0

Open in new window

then in the click event of your Next button have this
MyRowIndex = if(MyRowIndex < dtDonor.Rows.Count - 1, MyRowIndex + 1, MyRowIndex)
C1CountryOrigin.Text = dtDonor.Rows(MyRowIndex).Item("Country")

Open in new window

And you can have the Previous button have:
MyRowIndex = if(MyRowIndex = 0 , 0, MyRowIndex - 1)
C1CountryOrigin.Text = dtDonor.Rows(MyRowIndex).Item("Country")

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:nepaluz
ID: 38721181
Edited above to assign value to textbox.
Did that answer your question?
0
 

Author Comment

by:vcharles
ID: 38721808
Hi,

Juast read your post, will test it and get back to you.

Thanks,

Victor
0
 

Author Comment

by:vcharles
ID: 38721854
It worked! How do you move to first and last record?
Thanks,
0
 

Author Closing Comment

by:vcharles
ID: 38726814
Thank You!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now