在Win Application中将数据从XML检索到DataGridView [英] Retrieving data from XML to a DataGridView in Win Application
本文介绍了在Win Application中将数据从XML检索到DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我已经创建了一些XML数据,即:Sales_Details.xml现在我想在dataGridview控件上传输这些数据。我已经为该问题编写了代码,但它显示了一个错误,例如找不到表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;
}
推荐答案
错误表明在数据集中没有创建数据表,因此表[0]抛出异常。
您可以通过以下链接了解如何从xml读取数据。
http://msdn.microsoft.com/en-us/library/c7xcc35f.aspx [ ^ ]
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[^]
请参阅以下链接
http://support.microsoft.com/kb/311566 [ ^ ]
Refer below link
http://support.microsoft.com/kb/311566[^]
这篇关于在Win Application中将数据从XML检索到DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文