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

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>

mdreedAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
puffdaddy411Connect With a Mentor Commented:
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
 
Erick37Commented:
You could use the DataRow's ItemArray property to get or set the values in a row in one shot.
0
 
kdwoodCommented:

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
 
mdreedAuthor Commented:
I knew there should be an easier way !

Sorry, Erick.  puff beat you to it by 2 minutes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.