Results 1 to 3 of 3

Thread: [RESOLVED] Iterating through Datatable Columns

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Resolved [RESOLVED] Iterating through Datatable Columns

    Hi,
    I am wondering if it is possible to iterate using columns of datatable.

    thanks


    I have tried something like this:
    Code:
    Dim myCol As New DataColumn
    Dim myRow As DataRow = Nothing
    Dim myCell As New DataGridCell
    
    
    
            For Each myCol In myDt1.Columns
    
    
                For Each myCell In myCol
    
                    MsgBox(myCell.ToString)
    
    
                Next
    
    
    
            Next

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Iterating through Datatable Columns

    A DataTable is supposed to be basically an in-memory representation of a database table. Just like for a database table, in a DataTable the data is stored in the rows, not the column. The columns just describe the data, e.g. data type, size, nullability, etc. You need to loop through the rows of the table then, for each row, loop through the columns to get the data from the field from that column in the row. When indexing a DataRow, you can use an ordinal index, i.e. number, or you can use a column name or you can use the DataColumn itself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: Iterating through Datatable Columns

    Thank you JMC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width