"top" of datatable (newby)

  • Thread starter Thread starter Fred Nelson
  • Start date Start date
F

Fred Nelson

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
 
I solved it - it was too easy:

dim myDataView as new dataview(mytable)

Thanks!
 
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,
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
 

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

Back
Top