Click here to Skip to main content
11,642,216 members (65,347 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
Hi
I have created some XML data viz: Sales_Details.xml now I want to transfer such data on a dataGridview control. I have written code for that problem but it shows an error like "cannot find table 0". I don't understand why the error is appearing.


private void button1_Click(object sender, EventArgs e)
        {
            XmlTextReader tr = new XmlTextReader("E:\\Sales_Details.xml");
            DataSet ds = new DataSet();
            ds.ReadXml(tr);
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }
Posted 5-Feb-13 3:27am
Edited 5-Feb-13 3:48am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The error indicates that in the dataset no datatable is created, hence tables[0] is throwing an exception.

You can go through the following link on how to read data from xml.
http://msdn.microsoft.com/en-us/library/c7xcc35f.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 5 Feb 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