Posted by: Rhonda | December 9, 2007

Visual Studio DataSet Visualizer

I am still rather new to .NET, so there are many little tips and tricks that I still do not know. I was needing to easily see exactly what was populating a data set and someone at work showed me how to access the DataSet Visualizer.

To demonstrate this, the code below creates and populates a small data set.

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CrtDataSet
{
  class Program
  {
     static void Main(string[] args)
     {
        DataSet StateDS = new DataSet();
        DataTable statesTable = StateDS.Tables.Add();

        statesTable.Columns.Add("ID", typeof(int));
        statesTable.Columns.Add("StateCode", typeof(string));
        statesTable.Columns.Add("Description", typeof(string));
        statesTable.Columns.Add("Capital", typeof(string));

        statesTable.Rows.Add(1, "TX", "Texas", "Austin");
        statesTable.Rows.Add(2, "AR", "Arkansas", "Little Rock");
        statesTable.Rows.Add(3, "AZ", "Arizona", "Phoenix");
        statesTable.Rows.Add(4, "FL", "Florida", "Tallahassee");
        statesTable.Rows.Add(5, "LA", "Lousiana", "Baton Rouge");

        foreach (DataTable table in StateDS.Tables)
          {
             foreach (DataRow row in table.Rows)
             {
                Console.WriteLine(row["StateCode"] + " ~ " + row["Description"] + " ~ " + row["Capital"]);
             }
          }
     }
  }
}

To look at the contents of the data set via the DataSet Visualizer, set a breakpoint and run the program in debug mode. After the data set is populated, hover the mouse pointer over the data set name and click on the magnifying glass.

CLICK PICTURE FOR LARGER IMAGE

After clicking the magnifying glass icon, a grid appears showing the contents of the data set.

Great Sources for Visual Studio and .NET Tips


Leave a response

You must be logged in to post a comment.

Categories