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. Database & SysAdmin
  3. Database
  4. Opinion on how to handle a DataSet

Opinion on how to handle a DataSet

Scheduled Pinned Locked Moved Database
tutorialquestion
2 Posts 2 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
    stormydaniels
    wrote on last edited by
    #1

    I have a DataSet which contains three rows with 4 columns in each row. I want to print out the contents of the DataSet so I have written this:

    foreach (DataRow row in MyDataSet.Tables[0].Rows)
    for (int i = 0; i < MyDataSet.Tables[0].Columns.Count; i++)
    Console.WriteLine("Value {0}", row.ItemArray[i]);

    Is there a better way than having a for statement and looking at the ItemArray? I tried the following but I only get the column names:

    foreach (DataRow row in MyDataSet.Tables[0].Rows)
    foreach (DataColumn column in dsUpdates.Tables[0].Columns)
    Console.Write(column.ToString());

    If I am missing the basics can someone tell me where or what to read to understand handling DataSets? :)

    W 1 Reply Last reply
    0
    • S stormydaniels

      I have a DataSet which contains three rows with 4 columns in each row. I want to print out the contents of the DataSet so I have written this:

      foreach (DataRow row in MyDataSet.Tables[0].Rows)
      for (int i = 0; i < MyDataSet.Tables[0].Columns.Count; i++)
      Console.WriteLine("Value {0}", row.ItemArray[i]);

      Is there a better way than having a for statement and looking at the ItemArray? I tried the following but I only get the column names:

      foreach (DataRow row in MyDataSet.Tables[0].Rows)
      foreach (DataColumn column in dsUpdates.Tables[0].Columns)
      Console.Write(column.ToString());

      If I am missing the basics can someone tell me where or what to read to understand handling DataSets? :)

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Instead of

      Console.Write(column.ToString());

      try using the indexer for row like:

      Console.Write(row[column].ToString());

      The need to optimize rises from a bad design. My articles[^]

      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