I have a problem to save 2x Datatable into 1 xml file.
Im using c# .Net 4.6 +
DataTable dt = (DataTable)dataGridView1.DataSource;
DataTable dt1 = (DataTable)dataGridView2.DataSource;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "XML|*.xml";
if (sfd.ShowDialog() == DialogResult.OK)
{
try
{
dt.WriteXml(sfd.FileName);
dt1.WriteXml(sfd.FileName);
}
catch (Exception ex)
{
//Console.WriteLine(ex);
}
}
For loading data im using :
OpenFileDialog sfd = new OpenFileDialog();
sfd.Filter = "XML|*.xml";
if (sfd.ShowDialog() == DialogResult.OK)
{
string file = sfd.FileName;
try
{
dt.ReadXml(file);
dt1.ReadXml(file);
}
catch (Exception ex)
{
//Console.WriteLine(ex);
}
}
I want to save dt and dt1 to xml file then load it by 1 xml file.
How can i save it? When i use my code above then dt1 overwrites dt.