This is my button to save file:
private void metroButton12_Click(object sender, EventArgs e) // save
{
DataSet ds = (DataSet)dataGridView1.DataSource;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "XML|*.xml";
if (sfd.ShowDialog() == DialogResult.OK)
{
try
{
ds.Tables[0].WriteXml(sfd.FileName);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
I try to safe my datagridview to XML but nothing happpend when I choose file.
When I start console I see this:
System.NullReferenceException: The object reference was not set to an object instance.
My gridview look like:
ID Name
1 Michale
2 Noob
What am I doing here wrong?.. I saw a lot of thing's on the web but could not find any solutions in stackoverflow and other forums.
Please be patient for newbie guys. Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…