Solved

Best way to retrieve/process a single row in datatable.

Posted on 2011-03-25
4
453 Views
Last Modified: 2012-05-11
What is the most efficient way to retrieve and process a datatable with a single row?
What I have been doing thus far (because I don't know any other way) is something like the following.

Dim dr As DataRow
For Each dr In dt.Rows
        Return dr("CustID")
Next

Seems like I should be able to reference the contents of the single row with only one statement (i.e. dt.rows(0)<something>

0
Comment
Question by:mdreed
4 Comments
 
LVL 5

Accepted Solution

by:
puffdaddy411 earned 500 total points
ID: 35218386
If you know the index of the row, the following will return a Row object.

dt.Rows(0)


By adding ".ItemArray" you get an array of the items in that row.

dt.Rows(0).ItemArray


If you know your column names, you can reference those columns OR you can use index numbers.

dt.Rows(0).Item("ColumnNameORIndex")
0
 
LVL 32

Expert Comment

by:Erick37
ID: 35218403
You could use the DataRow's ItemArray property to get or set the values in a row in one shot.
0
 
LVL 10

Expert Comment

by:kdwood
ID: 35218438

If you just want to get the value, how about this:

Dim myCustID as Integer = dt.rows(0).item("CustID")

This would get the CustID value on row 0, the first row returned.

Regards,

Keith

0
 

Author Closing Comment

by:mdreed
ID: 35218469
I knew there should be an easier way !

Sorry, Erick.  puff beat you to it by 2 minutes.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

12 Experts available now in Live!

Get 1:1 Help Now