XML DataSet : DataSet XML « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » DataSet XMLScreenshots 
XML DataSet
  
Imports System.Data.SqlClient
Imports System.Windows.Forms
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class XmlTest
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.grid = New System.Windows.Forms.DataGridView
        Me.txtFile = New System.Windows.Forms.TextBox
        Me.cmdRead = New System.Windows.Forms.Button
        Me.cmdWrite = New System.Windows.Forms.Button
        CType(Me.grid, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        Me.grid.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom_
                    Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.grid.Location = New System.Drawing.Point(1143)
        Me.grid.Name = "grid"
        Me.grid.Size = New System.Drawing.Size(352212)
        Me.grid.TabIndex = 8
        '
        Me.txtFile.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtFile.Location = New System.Drawing.Point(1114)
        Me.txtFile.Size = New System.Drawing.Size(16021)
        Me.txtFile.TabIndex = 7
        Me.txtFile.Text = "c:\DataSet.xml"
        '
        Me.cmdRead.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdRead.Location = New System.Drawing.Point(27112)
        Me.cmdRead.Size = New System.Drawing.Size(9224)
        Me.cmdRead.TabIndex = 6
        Me.cmdRead.Text = "Read From XML"
        '
        Me.cmdWrite.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdWrite.Location = New System.Drawing.Point(18312)
        Me.cmdWrite.Size = New System.Drawing.Size(8424)
        Me.cmdWrite.TabIndex = 5
        Me.cmdWrite.Text = "Write to XML"
        '
        'XmlTest
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(375266)
        Me.Controls.Add(Me.grid)
        Me.Controls.Add(Me.txtFile)
        Me.Controls.Add(Me.cmdRead)
        Me.Controls.Add(Me.cmdWrite)
        Me.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "XmlTest"
        Me.Text = "XmlTest"
        CType(Me.grid, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents grid As System.Windows.Forms.DataGridView
    Friend WithEvents txtFile As System.Windows.Forms.TextBox
    Friend WithEvents cmdRead As System.Windows.Forms.Button
    Friend WithEvents cmdWrite As System.Windows.Forms.Button

    Private Sub cmdWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdWrite.Click
        Dim SQL As String = "SELECT * FROM Products"
        Dim Connect As String = "Data Source=localhost;Integrated Security=True;Initial Catalog=Northwind;"

        Dim con As New SqlConnection(Connect)
        Dim cmd As New SqlCommand(SQL, con)
        Dim adapter As New SqlDataAdapter(cmd)

        Dim dsNorthwind As New DataSet()
        con.Open()
        adapter.Fill(dsNorthwind, "Products")
        con.Close()
        dsNorthwind.WriteXmlSchema(txtFile.Text & ".xsd")
        dsNorthwind.WriteXml(txtFile.Text)
    End Sub

    Private Sub cmdRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdRead.Click
        Dim dsNorthwind As New DataSet()
        If System.IO.File.Exists(txtFile.TextThen
            dsNorthwind.ReadXml(txtFile.Text)
            grid.DataSource = dsNorthwind.Tables(0)
        Else
            MessageBox.Show("You need to create this file first.")
        End If
    End Sub

End Class

   
    
  
Related examples in the same category
1.Write Data in DataSet to XML fileWrite Data in DataSet to XML file
2.Generating XML from an ADO.NET DataSetGenerating XML from an ADO.NET DataSet
3.Display XML String from an ADO.NET DataSetDisplay XML String from an ADO.NET DataSet
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.