Solved

How to view data from a table with multiple rows

Posted on 2012-12-25
7
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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