Datagrid, dataset, and XML file > Won't save updates....
I have a program (I think this is how it works...) it loads an xml file into a datagrid, and ?binds? to a dataset.
User makes changes to datagrid and selects to save it to file .
Only problem is it doesnt always save/update. " maybe one out of 10 "
No errors or exception's are generated either.
this only fails when adding a new row, not when modifying current data.
Can anyone explain to me why?
here is my save method
public void SaveXmlFile(DataSet DataSet1, DataGrid dataGrid1 )
{
SaveFileDialog SaveFile = new SaveFileDialog();
SaveFile.DefaultExt = "xml";
// The Filter property requires a search string after the pipe ( | )
SaveFile.Filter = "XML documents (*.xml)|*.xml";
SaveFile.AddExtension = true;
SaveFile.ShowDialog();
if( SaveFile.FileName.Length > 0 )
{
//Save the file.
DataSet1.WriteXml( SaveFile.FileName );
Insert code here to process the files.
DataSet1.Clear();
//Reopen the file to check for saved changes
try
{
DataSet1.ReadXml(SaveFile.FileName);
dataGrid1.DataSource = DataSet1;
dataGrid1.DataMember = "TestProgramSet";
dataGrid1.CaptionText = dataGrid1.DataMember;
}
catch( Exception e )
{
MessageBox.Show( e.Message );
}
}
}//End SaveXmlFile
here is the load method
public void OpenXmlFile (string FilePath , DataSet DataSet1, DataGrid dataGrid1 )
{
DataSet1.Clear();
if ( File.Exists(FilePath) )
{
try
{
DataSet1.ReadXml(FilePath);
dataGrid1.DataSource = DataSet1;
dataGrid1.DataMember = "TestProgramSet";
dataGrid1.CaptionText = dataGrid1.DataMember;
}
catch( Exception e )
{
MessageBox.Show( e.Message );
}
}
}// End OpenXmlFile
here is the xml file named : ProgramSetPoints.xml
TPS_1
Sample between node 1 and 22
11.8
10.5
VDC
NA
3
TPS_2
Sample between node 7 and 31
.05
.01
mVdc
-.002
5
TPS_3
Current measurement at sleep mode
.002
.0001
mAmps
.000078
2
Thanks in advance.
Bill