Aaron

Aaron

  • NA
  • 1
  • 0

Save DataGridView to XML using LINQ

Oct 19 2009 4:40 PM
I have a unbound DataGridView that a user will enter data into and I want to append it to a xml file using LINQ.
Basically each xml file is a database for the selected unit.

The DataGridView has three columns in it which are: Part Number , QTY, and Description

The XML structure I have set up atm is:

 <WorkOrders>
<Config>
<UnitNumber></UnitNumber>
<EquipmentType></EquipmentType>
<DateCreated></DateCreated>
</Config>
<Record>
<RecordNumber>1</RecordNumber>
<WorkOrderNumber></WorkOrderNumber>
<Date></Date>
<EngineHours1></EngineHours1>
<EngineHours2></EngineHours2>
<TruckReportNumber></TruckReportNumber>
<Location></Location>
</Record>

The .xml file and the <config> part is created only once when a new piece of equipment is added.
When a user selects the equipment in the equipment list it opens the xml file and loads the config into the form this info will never change.


This is the code im usiing to save the <Records>

         xmlDoc.<WorkOrders>(0).Add(<Record>
<RecordNumber>1</RecordNumber>
<WorkOrderNumber><%= txt_workOrderNumber.Text %></WorkOrderNumber>
<Date><%= txt_date.Text %></Date>
<EngineHours1><%= txt_engineHours1.Text %></EngineHours1>
<EngineHours2><%= txt_engineHours2.Text %></EngineHours2>
<TruckReportNumber><%= txt_truckReportNumber.Text %></TruckReportNumber>
<Location><%= txt_location.Text %></Location>
</Record>)
xmlDoc.Save(xmlFile)

What im wanting to do is save all the data entered in the DataGridView to the same <Record> after the <Location> tag.