1
Answer

Datagrid, dataset, and XML file > Won't save updates....

Photo of bill_domenz

bill_domenz

20y
2.9k
1
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

Answers (1)

0
Photo of Mitesh Mistry
NA 27 1.4k 9y
it shows me this error : localhost.SqlParameter does not contain a constructor that takes 2 arguments
 
in
param[0] = new localhost.SqlParameter("KeyWord", b[1].ToString());
this line...
 
 
0
Photo of Khan Abrar Ahmed
NA 5.8k 200k 9y
Hi u can try like this
 
localhost.SqlParameter[] param = new localhost.SqlParameter[2];
param[0] = new localhost.SqlParameter("KeyWord", "Testing");
param[1] = new localhost.SqlParameter("PageSize", 20);
var objGetDetail = Obj1.GetDetail("SP_Related", param).Tables[0];