Getting the error: DataTable does not support schema inference from Xml When you are trying to read XML file to DataTable.
protected void btn_BindXMLtoGridView_Click(object sender, EventArgs e) { DataTable dt = new DataTable("Employees"); dt.ReadXml(MapPath("~/employees.xml")); GridView1.DataSource = dt; GridView1.DataBind(); }
This error throws when the datatable does not have any columns defined matching the XML FILE. To fix this, Create the DataTable with the columns matching the XML FILE.
The easy way is to read the XML file into DataSet and retrieve the table or bind to gridview if required.
protected void btn_BindXMLtoGridView_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(MapPath("~/employees.xml")); GridView1.DataSource = ds; GridView1.DataBind(); }