[CODE]Option Explicit
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim ConString As String
Dim strTableName As String
ConString = "Driver={mysql odbc 3.51 driver};Data Source=localhost;Database=tennis;" _
& "UID=root;pwd=admin"
conn.Open ConString
Open "d:\test1.xml " For Output As #1
Print #1, "<?xml version=""1.0"" ?>"
Print #1, "<result>"
Close
strTableName = "Players"
toXml strTableName, conn
strTableName = "matches"
toXml strTableName, conn
conn.Close
Open "d:\test1.xml " For Append As #1
Print #1, "</result>"
Close
End Sub
Private Sub toXml(tableName As String, con As ADODB.Connection)
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim s As Integer
Dim j As Integer
rs.CursorLocation = adUseClient
rs.Open "Select * from " & tableName, con, adOpenKeyset, adLockReadOnly, adCmdText
s = rs.Fields.Count
ReDim s_FieldName(s) As String
For i = 0 To s - 1
s_FieldName(i) = rs.Fields(i).Name
Next
Open "d:\test1.xml" For Append As #1
Print #1, "<table name=""" & tableName & """>"
For i = 0 To rs.RecordCount - 1
Print #1, "<row>"
For j = 0 To s - 1
Print #1, "<field name=""" & s_FieldName(j) & """>" & rs.Fields(j).Value & "</field>"
Next
Print #1, "</row>"
rs.MoveNext
Next
Print #1, "</table>"
Close
rs.Close
End Sub
[/CODE]