Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# obtain row values

C# obtain row values

Scheduled Pinned Locked Moved C#
csharptutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sc steinhayse
    wrote on last edited by
    #1

    In a C# 2010 application, I am working with data that is obtained from an excel spreadsheet 2007 or exccel 2010. I want to be ae to see all the values in a particular row. In the code below I want to see all the values in the row called dt.Rows[j]. Basically I want to know how to obtain all the values for the column called [k] in the statement dt.Rows[j][k]

    System.Data.DataTable dt = tt.GetExcelDataTable();
    for (int j = 0; j < dt.Rows.Count; j++)
    dt.Rows[j][k].ToString();

    Can you tell me how I can see the values I am looking for?

    L 1 Reply Last reply
    0
    • S sc steinhayse

      In a C# 2010 application, I am working with data that is obtained from an excel spreadsheet 2007 or exccel 2010. I want to be ae to see all the values in a particular row. In the code below I want to see all the values in the row called dt.Rows[j]. Basically I want to know how to obtain all the values for the column called [k] in the statement dt.Rows[j][k]

      System.Data.DataTable dt = tt.GetExcelDataTable();
      for (int j = 0; j < dt.Rows.Count; j++)
      dt.Rows[j][k].ToString();

      Can you tell me how I can see the values I am looking for?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This code will print your data one row in a line with data in each row comma separated

      System.Data.DataTable dt = tt.GetExcelDataTable();
      for (int j = 0; j < dt.Rows.Count; j++) {
      string rowData = string.Empty;
      for (int k = 0; k < dt.Columns.Count; k++) {
      rowData += dt.Rows[j][k].ToString() + ", ";
      }
      Console.WriteLine(rowData);
      }

      S P 2 Replies Last reply
      0
      • L Lost User

        This code will print your data one row in a line with data in each row comma separated

        System.Data.DataTable dt = tt.GetExcelDataTable();
        for (int j = 0; j < dt.Rows.Count; j++) {
        string rowData = string.Empty;
        for (int k = 0; k < dt.Columns.Count; k++) {
        rowData += dt.Rows[j][k].ToString() + ", ";
        }
        Console.WriteLine(rowData);
        }

        S Offline
        S Offline
        sc steinhayse
        wrote on last edited by
        #3

        I want to be able to see all the values while I am debugging the application. How would you accomplish this task?

        L P 2 Replies Last reply
        0
        • S sc steinhayse

          I want to be able to see all the values while I am debugging the application. How would you accomplish this task?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          The code I provided will print all the data one row in a line. However if you wish to see data in individual rows/columns, Visual Studio's debugging tools do a great job, just hover your mouse over the 'Rows' variable and Visual Studio will show you it's contents. Here[^] is a video that explains this feature.

          1 Reply Last reply
          0
          • S sc steinhayse

            I want to be able to see all the values while I am debugging the application. How would you accomplish this task?

            P Offline
            P Offline
            pramod hegde
            wrote on last edited by
            #5

            You can keep the break point in line 1 of your code.

            System.Data.DataTable dt = tt.GetExcelDataTable(); // line 1
            for (int j = 0; j < dt.Rows.Count; j++)
            dt.Rows[j][k].ToString();

            Now when the control reaches here, the line color changes to yellow. Press F10 now. Now, place the mouse over dt, you'll find a search icon, near the tip of the cursor. Click on that. It opens up the table for viewing.

            1 Reply Last reply
            0
            • L Lost User

              This code will print your data one row in a line with data in each row comma separated

              System.Data.DataTable dt = tt.GetExcelDataTable();
              for (int j = 0; j < dt.Rows.Count; j++) {
              string rowData = string.Empty;
              for (int k = 0; k < dt.Columns.Count; k++) {
              rowData += dt.Rows[j][k].ToString() + ", ";
              }
              Console.WriteLine(rowData);
              }

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I think your second for loop should have been edited after you pasted it. :rolleyes:

              L 1 Reply Last reply
              0
              • P PIEBALDconsult

                I think your second for loop should have been edited after you pasted it. :rolleyes:

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Edited. Thanks. You do have an eye for details. :-)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups