当前位置:编程学习 > C#/ASP.NET >>

VB.NET 2008读取XML或着INI连接SQL数据库的例子

求 VB.NET 2008读取XML或着INI连接SQL数据库的例子,非常感谢。
cep_yyd@163.com
在此谢过。 求程序代码 --------------------编程问答--------------------  


Private Function readXML(ByVal inXML As String, ByRef errmsg As String) As Integer
        Dim sfunction As String = "readXML"

        Dim sr As New System.IO.StringReader(inXML)
        Dim doc As New XmlDocument
        doc.Load(sr)
        Dim reader As New XmlNodeReader(doc)
        Try

            While reader.Read()
                Select Case reader.NodeType
                    Case XmlNodeType.Element
                        If reader.Name <> "MagellanGPS" Then
                            If reader.Name <> "User" Then
                                Select Case reader.Name
                                    Case "CGID"
                                        input.CGID = reader.ReadString
                                    Case "Lang"
                                        input.Lang = reader.ReadString
                                        If input.Lang = "" Then
                                            input.Lang = "en"
                                        End If
                                    Case "Status"
                                        input.Status = reader.ReadString
                                    Case "Username"
                                        input.Username = reader.ReadString
                                    Case "Password"
                                        input.Password = reader.ReadString
                                    Case "DateTime"
                                        input.Datetime = reader.ReadString
                                End Select
                            End If
                        End If
                End Select
            End While
            Return 1
        Catch ex As Exception
            errmsg = Err.GetException.Message
            Return -1
        End Try
    End Function
--------------------编程问答--------------------
Dim sqlconn As String
    Public Function GetDataTable(ByVal sCon As String, ByVal strSql As String) As DataTable
        Dim myDt As New DataTable
        Dim sqlConn As SqlConnection = New SqlConnection(sCon)
        Dim myCmd As SqlCommand = New SqlCommand(strSql, sqlConn)
        Dim myDa As New SqlDataAdapter(strSql, sqlConn)

        Try
            myDa.Fill(myDt)
        Catch er As Exception

        Finally
            sqlConn.Close()
        End Try
        Return myDt
    End Function

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim strConfig As String = Application.StartupPath + "\config.xml"
        Dim reader As New Xml.XmlTextReader(strConfig)
        Dim sql As String
        While (reader.Read())
            If (reader.IsStartElement()) Then
                Dim doc As New Xml.XmlDocument
                doc.Load(reader)
                Dim DataSources As Xml.XmlNode = doc.SelectSingleNode("dataSourceConfig").Item("DataSources")
                Dim xmlnode As Xml.XmlNode = DataSources.Item("add")
                sqlconn = xmlnode.Attributes("connectionString").InnerText
            End If
        End While
        reader.Close()
        sql = "select * from table"
        GetDataTable(sqlconn, sql)

    End Sub
================================
config.xml
<?xml version="1.0" encoding="utf-8" ?>
<dataSourceConfig>
  <DataSources>
    <add    
      connectionString="User id=User;Password=User;Data Source=test;"      
  />
  </DataSources>
</dataSourceConfig>

--------------------编程问答-------------------- 去google两个内容
1.读取xml
2.连接数据库 --------------------编程问答-------------------- http://blog.csdn.net/lidatgb/article/details/7196879,这里连接数据库写得很细,你参考一下 --------------------编程问答-------------------- 百度或者googe一下有源代码 --------------------编程问答--------------------
补充:.NET技术 ,  VB.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,