Solved

How to view data from a table with multiple rows

Posted on 2012-12-25
7
358 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

15 Experts available now in Live!

Get 1:1 Help Now