I try to fill a DataSet
with values from a XML file like this so 开发者_运维技巧I can then fill a DataGridView
with the values:
DataSet ds = new DataSet();
ds.ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.DataSource = "Products";
But I don't get anything. What am I doing wrong?
Are you sure your data loaded will be called Products
in your data set??
Try to verify by inspecting the tables in the dataset after you've loaded the data:
DataSet ds = new DataSet();
ds. ReadXml(@"C:\aaa.xml");
foreach(DataTable t in ds.Tables)
{
string tableName = t.TableName; // put a breakpoint here - inspect the table names
}
If you want to use simply show the first table loaded, try this snippet:
DataSet ds = new DataSet();
ds. ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].TableName;
DataSet ds = new DataSet();
ds.ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.Datamember= "Products";
精彩评论