Loop through all fields in a single record?

  • Thread starter Thread starter tedqn
  • Start date Start date
T

tedqn

In ASP, I can do it with

For Each objField In rsValue.Fields
//do something with objField.Value
Next

or
For i = 0 To rsValue.Fields.Count - 1 ..

I couldn't find any equivalent on how to do this with .net.
Can anybody help?
 
Well it depends on what kind of object you were looping through, e.g. to
loop through the columns in a DataTable object you could use something like
(in c#)

foreach(DataColumn CurrentColumn in MyDataTable.Columns)
{
Do something
}
 
Thanks for the suggestion. I've decided to use Dataset so that I can
loop through all the table rows & cells. Not sure if I can get it into
a Datatable directly instead of having to specify dsXXX.Tables(0),
through a DataAdapter
 
Not sure if I can get it into
a Datatable directly instead of having to specify dsXXX.Tables(0),
through a DataAdapter

Declare a reference to a DataTable and make it reference the table you
want to use:

DataTable table
table = dsXXX.tables(0)
 
In ADO.net 1.x you have to put a table into a dataset before you can do
anything with it, in ADO.net 2.0 you can use a DataTable on it's own and hte
only reason to add a DataTable to a DataSet is if you want to work with
multiple tables at once and do stuff like create relationships etc.
 

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