I have created the file but it cannot get loaded back to the gridview when i tried to browse it and upload, it shows the error of "Cannot find table 2". i don't know whats the problem because now the file that is being created it's no longer the same as the original file. original file table name its called data and after creating the file the table name became Table1
this is how i write to the file. mybe any suggestion on easiest way to write to the file will help.
private DataTable GetDataTableFromDataGridview(DataGridView _grid)
{
{
var _oDataTable = new DataTable();
object[] cellValues = new object[_grid.Columns.Count];
_oDataTable.Columns.Add("Name", typeof(string));
_oDataTable.Columns.Add("Value", typeof(string));
_oDataTable.Columns.Add("Font", typeof(string));
_oDataTable.Columns.Add("DateStamp", typeof(DateTime));
_oDataTable.Columns.Add("Comment", typeof(string));
foreach (DataGridViewRow row in _grid.Rows)
{
for (int i = 0; i < row.Cells.Count; i++)
{
cellValues[i] = row.Cells[i].Value;
}
_oDataTable.Rows.Add(cellValues.ToArray());
}
return _oDataTable;
}
}
Save button
private void btnSave_Click(object sender, EventArgs e)
{
string outputFilePath = txtInputfile.Text.Replace(_InputFileName, _OutFileName);
XDocument doc = XDocument.Load(outputFilePath);
DataTable dataTable = GetDataTableFromDataGridview(Gridview_Output);
DataSet dataSet = new DataSet();
dataSet.Tables.Add(dataTable);
dataSet.WriteXml(outputFilePath);
MessageBox.Show("New file created,testing ");
}
original file
<data name="Label" xml:space="preserve">
<value></value>
<comment>[Font][/Font][DateStamp][/DateStamp][Comment][/Comment]</comment>
</data>
<data name="Exit_Button" xml:space="preserve">
<value></value>
<comment>[Font][/Font][DateStamp][/DateStamp][Comment][/Comment]</comment>
</data>
<data name="Exit_Verify_Message" xml:space="preserve">
<value></value>
<comment>[Font][/Font][DateStamp][/DateStamp][Comment][/Comment]</comment>
results after creating new file
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<Name>FinEnrolment_CurrentSelectedUser_Label</Name>
<Value>dfsd</Value>
<Font>fdsf</Font>
<DateStamp>2015-02-03T10:56:50+02:00</DateStamp>
<Comment>dfd</Comment>
</Table1>
<Table1 />
</NewDataSe>