您的位置:首页 > 编程语言 > C#

C#将xml文件数据导入datagridview中

2012-12-19 12:26 344 查看
public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

string strPath=null;//文件咱径

private void button1_Click(object sender, EventArgs e)

{

openFileDialog1.Filter = "xml文件|*.xml";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

strPath = openFileDialog1.FileName;

}

}

private void button2_Click(object sender, EventArgs e)

{

if (strPath != null)

{

DataSet ds = new DataSet();

ds.ReadXmlSchema(strPath);

ds.ReadXml(strPath);

dataGridView1.DataSource = ds.Tables[0].DefaultView;

}

else

{

MessageBox.Show("请选择XML文件");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: