Click here to Skip to main content
11,648,785 members (84,939 online)
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 2: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 F-ES Sitecore 409
1 CPallini 370
2 OriginalGriff 334
3 Kornfeld Eliyahu Peter 324
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,512
1 Sergey Alexandrovich Kryukov 1,022
2 jyo.net 994
3 DamithSL 986
4 CPallini 945


Advertise | Privacy | Mobile
Web03 | 2.8.150804.4 | Last Updated 31 May 2013
Copyright © CodeProject, 1999-2015
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