Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 C# C#4.0
here is my code i read a XML doc and get all their values in dataset, how to take that all dataset values in gridview. i need the output like the same dataset visualizer.

 
 

XmlDocument doc = new XmlDocument();
            doc.Load(PATH);
            
            DataSet ds = new DataSet();
            ds.ReadXml(PATH);
Posted 30-May-13 3:18am
Comments
Ankur\m/ at 30-May-13 8:31am
   
Create a gridview, set it's DataSource property to required DataTable from the DataSet and then call DataBind().
You will have to set autogenerate columns property to true if you don't know the columns from before.
TRY!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

/ Here your xml file
string xmlFile = "Data.xml";
 
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile, XmlReadMode.InferSchema);
 
// Then display informations to test
foreach (DataTable table in dataSet.Tables)
{
    Console.WriteLine(table);
    for (int i = 0; i < table.Columns.Count; ++i)
        Console.Write("\t" + table.Columns[i].ColumnName.Substring(0, Math.Min(6, table.Columns[i].ColumnName.Length)));
    Console.WriteLine();
    foreach (var row in table.AsEnumerable())
    {
        for (int i = 0; i < table.Columns.Count; ++i)
        {
            Console.Write("\t" + row[i]);
        }
        Console.WriteLine();
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

XmlDocument doc = new XmlDocument();
doc.Load(PATH);

DataSet ds = new DataSet();
ds.ReadXml(PATH);
 
if you are using DataGridView use below
 
datagridview1.Datasource=ds.Tables[0];
 
if you are using GridView use below
gridview1.Datasource=ds.Tables[0];
gridview1.Databind();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 31 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100