Board index » Visual Studio » "top" of datatable (newby)

"top" of datatable (newby)

Visual Studio255
Hi:



I have created a datatable and I'm able to access it by key values.



I need to be able to go to the "top" of the datatable and process

records sequentially until they are completed.



I can't figure out the command to set me to the top or "beginning" and

then read. (datatable.select?)



Any help in the steps to do this would be greatly appreciated!



Thanks,



Fred


-
 

Re:"top" of datatable (newby)

I solved it - it was too easy:



dim myDataView as new dataview(mytable)



Thanks!





Fred Nelson wrote:

Quote
Hi:



I have created a datatable and I'm able to access it by key values.



I need to be able to go to the "top" of the datatable and process

records sequentially until they are completed.



I can't figure out the command to set me to the top or "beginning" and

then read. (datatable.select?)



Any help in the steps to do this would be greatly appreciated!



Thanks,



Fred

-

Re:"top" of datatable (newby)

Fred,



Dataviews are good if you want to create a temporary filter. You still have

to create a loop to read through the file. Just to read the file from start

to finish most people use the following:



Dim dr As DataRow

For Each dr in MyTable

... Do something using "dr." to reference each field

Next



Regards

"Fred Nelson" <fred@smartybird.com>wrote in message

Quote
Hi:



I have created a datatable and I'm able to access it by key values.



I need to be able to go to the "top" of the datatable and process

records sequentially until they are completed.



I can't figure out the command to set me to the top or "beginning" and

then read. (datatable.select?)



Any help in the steps to do this would be greatly appreciated!



Thanks,



Fred





-

Re:"top" of datatable (newby)

Fred,

In addition to the other examples you can use:



Dim table As DataTable



For Each row As DataRow in table.Rows

' do something with the row

Next



For Each row As DataRow in table.Select()

' do something with the row

Next



Dim view As New DataView(table)

For Each row As DataRowView in view

' do something with the row

Next



Each is useful in their own right. Most of the time I use the first.

DataTable & DataView allow you to filter rows. The second is useful if you

want to delete selected rows, as DataTable.Select returns an array of rows,

allowing you to use DataRow.Delete to delete the row from the DataTable

itself, Also DataTable.Select is overloaded so you can sort & filter the

returned rows. The DataView has some very flexible sorting, searching, and

filtering abilities, plus you can bind to it.



I recommend David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS

Press. As it is a good tutorial on ADO.NET as well as a good desk reference

once you know ADO.NET.



Hope this helps

Jay



"Fred Nelson" <fred@smartybird.com>wrote in message

Quote
Hi:



I have created a datatable and I'm able to access it by key values.



I need to be able to go to the "top" of the datatable and process

records sequentially until they are completed.



I can't figure out the command to set me to the top or "beginning" and

then read. (datatable.select?)



Any help in the steps to do this would be greatly appreciated!



Thanks,



Fred





-