datatable

M

Mark Kurten

in the following code

Dim row As DataRow = ds.Tables("TestTable").Select()(0)

I found this in an example. I'm wondering what does the (0) at the end do?
I can't find any reference to that in the online help for vb.net (looking
under datatable or datarow)

thanks.
 
R

Richard K Bethell

The example you've shown appears to have a significant error (more on that
in a second), but I would guess it intends to grab you the first row, and
only the first row, of this table, as opposed to an array.

Now here is where it gets interesting. I am unaware of any Select() method
for the DataTable object, or any member with this name. What you would
probably need here would be:

Dim row As DataRow = ds.Tables("TestTable").Rows(0)

R.
 
M

Marina

Select returns an array of DataRow objects fitting the criteria (which you
should pass in). When you say '(0)', that just means the row at index 0,
a.k.a. the first row in the results.

Now, since you are not passing in any criteria, it returns them all, sorted
by primary key, if there is one.
 
M

Marina

Oh, and by the way, DataTable has this method fully documented. It documents
the return type - and you can look at the return type for information on
what properties/methods that has.
 
G

Guest

Actually there is a select method that you can call for a datatable. It's used to filter records from the datatable

i.e MyDataTable.Select("State = 'CA'") will return a datarow collection of rows that match your filter criteria.
 
M

Mark Kurten

thank you all...


Marina said:
Oh, and by the way, DataTable has this method fully documented. It documents
the return type - and you can look at the return type for information on
what properties/methods that has.
 
S

Steven Cheng[MSFT]

Hi Mark,


Thanks for posting in the community!
From your description, you are asking about what is the meaning of the
"(0)" in the below code:
Dim row as DataRow = ds.Tables("TestTable").Select()(0) mean.
Also, you're looking for some document on this.

As the first problem, I think Richard and Marina's answers are quite
correct. And here are some online documentation on this topic:
#.NET Framework Class Library DataTable.Select Method ()
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatadatatablec
lassselecttopic1.asp?frame=true

#.NET Framework Developer's Guide Viewing Data in a Table
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconviewingdataindatat
able.asp?frame=true

Please check out the above items to see whether they're helpful to you.
Meanwhile, if you have any questions, please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top