datasets.vb

来自「wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重」· VB 代码 · 共 80 行

VB
80
字号
Option Explicit On
Option Strict On

Imports System.Data
Imports System.IO

Public Class DataSets
    Private strPath As String
    Private strFile As String
    Private strXML As String
    Private Const strIEFile As String = "\Program Files\Internet Explorer\Iexplore.exe"

    Private Sub DataSets_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        strPath = Application.StartupPath
    End Sub

    Private Sub btnNWAttribs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNWAttribs.Click
        Dim dsAttribs As New DataSet
        strFile = strPath + "\NWAttribs.xml"
        If File.Exists(strFile) Then
            With dsAttribs
                'Infer the schema
                .ReadXml(strFile)
                'Write the output document
                Dim strXmlFile As String = strPath + "\NWAttribs.xml"
                .WriteXml(strXmlFile, XmlWriteMode.IgnoreSchema)
                'Write the inferred schema
                Dim strXsdFile As String = strPath + "\NWAttribs.xsd"
                .WriteXmlSchema(strXsdFile)
                Shell("""" + strIEFile + """ " + strXmlFile, AppWinStyle.NormalFocus)
            End With
        End If
    End Sub

    Private Sub btnLoadNwDs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadNwDs.Click
        With Me.NorthwindDS
            strFile = strPath + "\NorthwindDS.xml"
            If File.Exists(strFile) Then
                .ReadXml(strFile)
                strFile = strPath + "\Output.xml"
                .WriteXml(strFile, XmlWriteMode.IgnoreSchema)
                Shell("""" + strIEFile + """ " + strFile, AppWinStyle.NormalFocus)
            End If
        End With
    End Sub

    Private Sub btnShowCustDs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowCustDs.Click
        strFile = strPath + "\CustomersDS.xsd"
        If File.Exists(strFile) Then
            Shell("""" + strIEFile + """ " + strFile, AppWinStyle.NormalFocus)
        End If
    End Sub

    Private Sub btnShowNwXsd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowNwXsd.Click
        strFile = strPath + "\NorthwindDS.xsd"
        If File.Exists(strFile) Then
            Shell("""" + strIEFile + """ " + strFile, AppWinStyle.NormalFocus)
        End If
    End Sub

    Private Sub btnShowNwAttribsXsd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowNwAttribsXsd.Click
        strFile = strPath + "\NWAttribs.xsd"
        If File.Exists(strFile) Then
            Shell("""" + strIEFile + """ " + strFile, AppWinStyle.NormalFocus)
        End If
    End Sub

    Private Sub btnLoadCustsDs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadCustsDs.Click
        With Me.CustomersDS
            strFile = strPath + "\CustomersDS.xml"
            If File.Exists(strFile) Then
                .ReadXml(strFile)
                strFile = strPath + "\Output.xml"
                .WriteXml(strFile, XmlWriteMode.IgnoreSchema)
                Shell("""" + strIEFile + """ " + strFile, AppWinStyle.NormalFocus)
            End If
        End With
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?