Solved

How to view data from a table with multiple rows

Posted on 2012-12-25
7
359 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 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