Recently I was in the need to serialize a DataTable as a string for further processing (storing in a file).
So I asked myself: How to serialize a DataTa
You can also try writing out the DataTable to XML which works just as nicely:
Dim dt As DataTable
Dim DataTableAsXMLString As String
'...code to populate DataTable
Using sw As New StringWriter()
dt.WriteXml(sw)
DataTableAsXMLString = sw.ToString()
End Using
...then if needed you can convert the XML right back to a DataTable:
Dim ds As New DataSet
Dim dt2 As DataTable
Using sr As New StringReader(DataTableAsXMLString)
ds.ReadXml(sr)
dt2 = ds.Tables(0)
End Using