Dim tb As New DataTable("Table")
tb.Columns.Add("Name", Type.[GetType]("System.String"))
tb.Columns.Add("Currency", Type.[GetType]("System.String"))
Dim st As [String] = ""
If dg.Name = "DataGridView1" Then
st = "D:\text.xml"
ElseIf dg.Name = "DataGridView2" Then
st = "D:\text1.xml"
End If
For Each row As DataGridViewRow In dg.Rows
Dim r As DataRow = tb.NewRow()
r("Name") = row.Cells(0).Value 'row1 cell 1
r("Currency") = row.Cells(1).Value 'row1 cell2
tb.Rows.Add(r)
Next
tb.WriteXml(st)
Problem:
if dg.Rows.count=0, for each wont execute & when comes to tb.writexml(st),
I expect xml file to look like
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<Table>
<Sno> </Sno>
<Code> </Code>
</Table>
</DocumentElement>
but coming wrongly as
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
</Table>
</DocumentElement>
Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator