通过调用CreateDataSetFromXml取得XML数据 Imports System.Xml Public Const FILE_CONFIG = "MZZ.xml" Public Const PATH_CONFIG = "/XML/" Dim dstXML As DataSet Dim tblXML_DB As DataTable Dim dtCod As New DataTable Dim strSQL As String = "" clsPublic.pstrAppPath = System.Windows.Forms.Application.StartupPath'启动程序路径 '启动程序上级目录(InStrRev是取得最后显示/的位置) clsPublic.pstrAppPath = Mid(clsPublic.pstrAppPath, 1, InStrRev(clsPublic.pstrAppPath, "/", ) - 1) '只能启动一个程序 If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then Exit Sub End If '读取XML数据(QDIS节点,作为一个table,所以是dstXML.Tables(0)) dstXML = CreateDataSetFromXml(FILE_CONFIG) tblXML_DB = dstXML.Tables(0) clsDBBase.Uid = tblXML_DB.Rows(0).Item("UserId") clsDBBase.Psw = tblXML_DB.Rows(0).Item("Password") clsDBBase.Dsn = tblXML_DB.Rows(0).Item("DataSource") '(APPL节点,作为一个table,所以是dstXML.Tables(1)) clsPublic.Timer_Interval = CType(dstXML.Tables(1).Rows(0).Item("Interval"), Integer) '内存整理 GC.Collect() Public Function CreateDataSetFromXml(ByVal strFileName As String) As DataSet Dim xmlDoc As XmlDataDocument = New XmlDataDocument Dim xmlReader As StreamReader = Nothing Try xmlReader = New StreamReader(clsPublic.pstrAppPath & PATH_CONFIG & strFileName) xmlDoc.DataSet.ReadXml(xmlReader, XmlReadMode.Auto) Return xmlDoc.DataSet.Copy Catch ex As Exception Return Nothing Finally Try If Not xmlReader Is Nothing Then xmlReader.Close() xmlReader = Nothing End If xmlDoc = Nothing Catch ex As Exception End Try End Try End Function <?xml version="1.0" standalone="yes"?> <NewDataSet> <QDIS> <UserId>MZZ</UserId> <Password>MZZ</Password> <DataSource>MZZ</DataSource> </QDIS> <APPL> <Interval>10</Interval> </APPL> <AppSettings> <!--中心点X--> <StartPointX>4400.0</StartPointX> <!--中心点Y--> <StartPointY>62230.0</StartPointY> </AppSettings> </NewDataSet>