本程序是通过 vb 6.0 编译。 Private Sub Command2_Click() Set tdc = CreateObject("TDApiOle80.TDConnection") tdc.InitConnectionEx "http://lab11:8888/qcbin" tdc.ConnectProjectEx "DEFAULT", "QualityCenter_Demo", "alex_qc", "" Set com = tdc.Command com.CommandText = Text3.Text '获得sql 语句 'select bg_bug_id from bug Set Recset = com.Execute recCnt = Recset.ColCount Set xmlDoc = CreateObject("Microsoft.XMLDOM") Set xnRows = xmlDoc.createNode(1, "Rows", "") '创建root xmlDoc.appendChild (xnRows) For i = 1 To Recset.recordCount Set xnRow = xmlDoc.createNode(1, "Row", "") '创建孩子 xnRows.appendChild (xnRow) For j = 0 To Recset.ColCount - 1 Set xnCell = xmlDoc.createNode(1, "_" & j, "") '取得列名 xnCell.Text = Recset.FieldValue(j) '将列的值加到xnCell上或者说是直接给列赋值 xnRow.appendChild (xnCell) Next Recset.Next Next xmlDoc.save ("d:/1.xml") '将xml文件保存 End Sub 1.xml 文件内容如下: - <Rows> - <Row> <_0>1</_0> </Row> - <Row> <_0>2</_0> </Row> - <Row> <_0>3</_0> </Row> -</Rows>