Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-25
4
Medium Priority
?
468 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

772 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