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>