본문 바로가기

자료

[C#/vb.net] DataTable 내용을 XML로 저장 및 불러오기

728x90

Example 1:)

Write:

dt1.TableName = "MyDataTable"

dt1.WriteXmlSchema(Application.StartupPath + "\test_sh.xml", True)

dt1.WriteXml(Application.StartupPath + "\test_dt.xml", True)

Read:

dt2 = New DataTable

dt2.ReadXmlSchema(Application.StartupPath + "\test_sh.xml")

dt2.ReadXml(Application.StartupPath + "\test_dt.xml")

Example 2:)

Write:

Dim writer As System.IO.StringWriter = New System.IO.StringWriter()

customerTable.WriteXml(writer, XmlWriteMode.WriteSchema, False)

Write:

writer = New System.IO.StringWriter()

customerTable.WriteXml(writer, XmlWriteMode.WriteSchema, True)

Example 3:)

Write:

Dim xmlStream As System.IO.MemoryStream = New System.IO.MemoryStream()

table.WriteXml(xmlStream, XmlWriteMode.WriteSchema)

xmlStream.Position = 0

Read:

Dim newTable As DataTable = New DataTable()

newTable.ReadXml(xmlStream)

Example 4:)

Write:

Dim fileName As String = "C:\TestData.xml"

table.WriteXml(fileName, XmlWriteMode.WriteSchema)

Read:

Dim newTable As DataTable = New DataTable()

newTable.ReadXml(fileName)

728x90