Results 1 to 2 of 2

Thread: DataTable/Excel

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    DataTable/Excel

    I have a datatable populated with data from an Excel spreadsheet.

    What I want to do now is loop through each row and column.

    I want to find out on each row and the current column, on if the columnName is the specified start column name. It will then continue on collecting the names of columns until the specified end column name is specified.

    this means that we can then go through each row but starting to get data based on the startcolumn and the end column

    any ideas?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: DataTable/Excel

    Is this what you are trying to do?
    Code:
    DataTable dt;
    
                dt = PopulateMyDataTable();
    
                int iStart = 0;
                int iEnd = 0;
    
                // Figure out our starting and ending columns
                for (int i = 0; i < dt.Columns.Count;i++ )
                {
                    if (dt.Columns[i].ColumnName == "My Start Column")
                        iStart = i;
                    if (dt.Columns[i].ColumnName == "My End Column")
                        iEnd = i;
                    
                }
    
                if (iStart > 0 && iEnd > 0 && iStart < iEnd)
                {
                    // Loop through the rows
                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        DataRow objRow = dt.Rows[j];
                        for (int k = iStart; k <= iEnd; k++)
                        {
                            // Read Values from here
                        }
    
    
                    }
                }

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