把DATASET转成XML(主从表结构)
Dim objConn As OracleConnection
Dim objDataAdapter As OracleDataAdapter
Dim strConn As String = "user id=scott;password=tiger;data source=orcl"
Dim strSql As String
Dim ds As DataSet
Dim objXmlDataDoc As XmlDataDocument
Try
objConn = New OracleConnection(strConn)
ds = New DataSet("DeptEmp")
strSql = "select * from emp"
objDataAdapter = New OracleDataAdapter(strSql, objConn)
objDataAdapter.Fill(ds, "Employee")
strSql = "select * from dept"
objDataAdapter.SelectCommand.CommandText = strSql
objDataAdapter.Fill(ds, "Dept")
ds.CaseSensitive = False
ds.Relations.Add("DeptEmployees", _
ds.Tables("Dept").Columns("DeptNo"), _
ds.Tables("Employee").Columns("DeptNo")).Nested = True
ds.WriteXml("DeptEmployees.xml")
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.ReadLine()
End Try
保存以后的XML的格式
<?xml version="1.0"?>
<testds>
<dt1 name="dt1">
<id>a</id>
<dt1c2>111</dt1c2>
<dt2 name="dt2">
<dt2c1>d2</dt2c1>
<dt2c2>adad</dt2c2>
</dt2>
</dt1>
</testds>
Dim objDataAdapter As OracleDataAdapter
Dim strConn As String = "user id=scott;password=tiger;data source=orcl"
Dim strSql As String
Dim ds As DataSet
Dim objXmlDataDoc As XmlDataDocument
Try
objConn = New OracleConnection(strConn)
ds = New DataSet("DeptEmp")
strSql = "select * from emp"
objDataAdapter = New OracleDataAdapter(strSql, objConn)
objDataAdapter.Fill(ds, "Employee")
strSql = "select * from dept"
objDataAdapter.SelectCommand.CommandText = strSql
objDataAdapter.Fill(ds, "Dept")
ds.CaseSensitive = False
ds.Relations.Add("DeptEmployees", _
ds.Tables("Dept").Columns("DeptNo"), _
ds.Tables("Employee").Columns("DeptNo")).Nested = True
ds.WriteXml("DeptEmployees.xml")
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.ReadLine()
End Try
保存以后的XML的格式
<?xml version="1.0"?>
<testds>
<dt1 name="dt1">
<id>a</id>
<dt1c2>111</dt1c2>
<dt2 name="dt2">
<dt2c1>d2</dt2c1>
<dt2c2>adad</dt2c2>
</dt2>
</dt1>
</testds>