0
的XML文件,但它不能让装回当我试图浏览并上传GridView控件,它显示的错误“无法找到表2”。我不知道最新的问题,因为现在正在创建的文件不再与原始文件相同。原始文件表名其称为数据和创建文件后,该表的名字成为表1如何重装创建成我所创建的文件在DataGridView
这是我写的文件。对于写入文件最简单的方法,任何建议都会有所帮助。
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;
}
}
保存按钮
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 ");
}
原始文件
<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>
结果创建新文件之后
<?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>