Reputation: 337
I have a problem filling datagridview with text/values from dataset (NOT MYSQL!!).
I have dataset table filled when .xml file is imported.
DataSet1 dsDataSet1 = new DataSet1();
String XMLCompanies = Application.StartupPath + @"\XMLCompanies.xml";
dsDataSet1.ReadXml(XMLCompanies);
I am trying to display content of dataset in datagridview so I add line:
dataGridView1.DataSource = dataSet1.Tables["Companies"];
however I only get rows headers names but without any other data.
XMLCompanies.xml data:
<?xml version="1.0" standalone="true"?>
-<DataSet1 xmlns="http://tempuri.org/DataSet1.xsd">
-<Companies>
<ID>1234</ID>
<Company>TEST inc</Company>
<Address>Address test</Address>
<ZIP>12345678</ZIP>
<City>City TEST</City>
<TAXnumber>70769232</TAXnumber>
</Companies>
</DataSet1>
Any simple solution to display dataset text/values in datagridview would be great. Thanks!
Upvotes: 0
Views: 196
Reputation: 222722
XMLCompanies.xml
<?xml version="1.0" standalone="yes"?>
<DataSet1 xmlns="http://tempuri.org/DataSet1.xsd">
<Companies>
<ID>1234</ID>
<Company>TEST inc</Company>
<Address>Address test</Address>
<ZIP>12345678</ZIP>
<City>City TEST</City>
<TAXnumber>70769232</TAXnumber>
</Companies>
</DataSet1>
Code:
DataSet xmlDataSet = new DataSet();
String XMLCompanies = Application.StartupPath + @"\XMLCompanies.xml";
xmlDataSet.ReadXml(XMLCompanies);
this.dataGridView1.DataSource = xmlDataSet.Tables[0];
Output:
Upvotes: 1