Pomster
Pomster

Reputation: 15197

Show the data in a dataset?

I am trying to view the data in a Dataset, I don't mind what view it is, i can print it out in a text file or show it in a Datagrid I am just trying to discover whats in side. I am testing a Webservice to see if it returns results and i have it returning a Dataset.

ServiceReference1.PropertiesSoapClient ws1 = new ServiceReference1.PropertiesSoapClient();
            ws1.Open();

 DataSet datasetprint = new DataSet();
            if (ws1 != null)
            {
                ServiceReference1.ReturnValuationRequest request = new ServiceReference1.ReturnValuationRequest(UserID, trackingNumber);
                ServiceReference1.ReturnValuationResponse response = ws1.ReturnValuation(request);
                if (response.ReturnValuationResult != null)
                {
                    DataSet ds = response.ReturnValuationResult;
                    datasetprint = ds;            
                }
            }

Whats the best way for me to view its Content?


Edit:

I would prefer not just looking thought the break point as its endless with so much data i that does not make sense.

enter image description here

I would prefer viewing it in a datagrid or even in a Textfile.

Upvotes: 2

Views: 26066

Answers (7)

Kabindas
Kabindas

Reputation: 832

Export it to XML on filesystem and use any reader to inspect

ds.WriteXml("c:\\test.xml")

Upvotes: 2

Fanuel Reyes
Fanuel Reyes

Reputation: 11

If you would like to populate a DataGridView simply assign a table from the Dataset to the DataGridView datasource. Example:

DataGridView1.DataSource = dataset.Tables[0]

Upvotes: 1

cjb110
cjb110

Reputation: 1491

Do you mean something like:

foreach (DataRow row in dt.Rows)
{
    foreach (DataColumn col in dt.Columns)
        textBox.Text += row[col] + ", ";

    textBox.Text += "\r\n";
}

Crude but will work. I'm sure I had a more elegant and flexible solution using LINQ somewhere...

Try searching for DataSet to CSV, as that, at some point, will convert each dataset row into a delimited string, which is basically what your after.

Upvotes: 1

cjb110
cjb110

Reputation: 1491

One alternative is highlighted in this SO answer: StackOverflow: "How to convert a DataTable to a string in C#?"

Basically:

using(var writer = new StringWriter())
{
  myDataSet.WriteXml(writer);
  Console.WriteLine(writer.ToString());
}

Is that good enough?

Upvotes: 1

MrFox
MrFox

Reputation: 5126

You should use the looking class icon. The mouse hover menu is comprised of the following elements:

  • expand object properties ('+' icon)
  • variable name ('datasetprint')
  • looking glass (image)
  • dropdown menu (donno what for :P)
  • object type (System.Data.DataSet)
  • pin icon (so the hover menu stays in place)

When you press the looking glass a datagridview opens, you can view the data here or copy it to view elsewhere.

Upvotes: 4

Gerard Sexton
Gerard Sexton

Reputation: 3210

If you want to view it without any additional code, just use the debugger to set a breakpoint after the dataset gets populated and hover over the dataset variable name, a little popup comes up and then click the little magnifying glass in the popup.

Its called the dataset visualizer, I think.

Just a note, it can timeout your debugging session and do some other funky stuff. If it times out then you won't be able to continue stepping through your code.

Upvotes: 14

Dennis Traub
Dennis Traub

Reputation: 51664

If you just want to know what's inside the DataSet, set a breakpoint at the following line, debug, and look what's inside:

datasetprint = ds;  

Upvotes: 0

Related Questions