Question datagrid to xml

homer.favenir

New member
Joined
Aug 17, 2009
Messages
1
Programming Experience
Beginner
hi,
i have a datagridview control and with records in it.
and i want to write the selected row in an xml file


how can i achieve it

VB.NET:
Do While rowCount < DataGridView1.Rows.Count()
            gridItem = DataGridView1.Item(0, rowCount).Value
            Dim sp_getID As String
            sp_getID = "sp_EF_getEmpID"
            Dim cmd As New SqlCommand(sp_getID, SQLConn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@id", gridItem)
            result = cmd.ExecuteScalar().ToString()
            If result = "" Then
                empidList.ListBox1.Items.Add(gridItem) [COLOR="red"][B]'append/write this row in an xml file[/B][/COLOR]
                
            End If
            rowCount += 1
           Loop

Please kindly help

tia
 
I'd probably remove the row from the current datatable, and put it in another datatable, then write the whole thing to disk:

VB.NET:
Dim xmlDt as New XyzDatatable
ForEach ro as XyzDataRow in xyzDatatable
  If (some test) Then
    xyzDatatabe.RemoveXyzRow(ro)
    xmlDt.AddXyzRow(ro)
  End If
Next
xmlDt.WriteXml("C:\the.xml")
 
Back
Top