我尝试使用这样的XML文件中的DataSet
填充值,这样我就可以使用以下值填充DataGridView
:
DataSet ds = new DataSet();
ds.ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.DataSource = "Products";
但我什么都没得到。我做错了什么?
答案 0 :(得分:2)
您确定加载的数据会在数据集中被调用Products
吗?
尝试通过在加载数据后检查数据集中的表来进行验证:
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
}
如果您想使用只是显示加载的第一个表,请尝试以下代码段:
DataSet ds = new DataSet();
ds. ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].TableName;
答案 1 :(得分:1)
DataSet ds = new DataSet();
ds.ReadXml(@"C:\aaa.xml");
dataGridView1.DataSource = ds;
dataGridView1.Datamember= "Products";