Solved

How to view data from a table with multiple rows

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

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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