Loop through all fields in a single record?

Discussion in 'ASP .Net' started by tedqn@yahoo.com, Apr 27, 2006.

  1. Guest

    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?
     
    , Apr 27, 2006
    #1
    1. Advertising

  2. 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
    }



    "" wrote:

    > 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?
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Apr 27, 2006
    #2
    1. Advertising

  3. Guest

    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
     
    , Apr 28, 2006
    #3
  4. > 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)
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Apr 28, 2006
    #4
  5. 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.

    "Göran Andersson" wrote:

    > > 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)
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Apr 28, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AFN
    Replies:
    8
    Views:
    7,755
    =?Utf-8?B?QW5keSBaIFNtaXRo?=
    Jun 16, 2004
  2. Chris
    Replies:
    1
    Views:
    524
    =?Utf-8?B?UmljaA==?=
    Apr 29, 2005
  3. Eric Layman
    Replies:
    3
    Views:
    665
    Rad [Visual C# MVP]
    Apr 14, 2007
  4. Alan Z. Scharf

    Single record display paging through dataset

    Alan Z. Scharf, Jul 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    249
    Lewis Wang [MSFT]
    Jul 23, 2003
  5. Isaac Won
    Replies:
    9
    Views:
    460
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page