if (dgvScore.Rows.Count == 0)
{
MessageBox.Show("没有数据可导出!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
this.saveFileDialog1.FileName ="成绩查询数据--"+DateTime.Now.ToString("yy/MM/dd hh:mm:ss");
this.saveFileDialog1.Filter = "XML文件(*.xml)|*.xml";
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
DataSet ds = new DataSet();
DataTable dt = dtSource.Copy();
ds.Tables.Add(dt);
ds.WriteXml(this.saveFileDialog1.FileName);
MessageBox.Show("数据成功保存到" + this.saveFileDialog1.FileName, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
{
MessageBox.Show("没有数据可导出!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
this.saveFileDialog1.FileName ="成绩查询数据--"+DateTime.Now.ToString("yy/MM/dd hh:mm:ss");
this.saveFileDialog1.Filter = "XML文件(*.xml)|*.xml";
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
DataSet ds = new DataSet();
DataTable dt = dtSource.Copy();
ds.Tables.Add(dt);
ds.WriteXml(this.saveFileDialog1.FileName);
MessageBox.Show("数据成功保存到" + this.saveFileDialog1.FileName, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
本文介绍了一个简单的成绩数据导出为XML文件的过程。首先检查DataGridView中是否有数据待导出,若无则弹出提示框;若有,则通过SaveFileDialog让用户选择保存路径,并将DataGridView中的数据写入指定的XML文件。
1399

被折叠的 条评论
为什么被折叠?



