Vb.Net-Informations.com

  How to create an XML file in VB.NET using Dataset




   Categories

    HOME
    VB.NET
    CSHARP

 
   














How to create an XML file in VB.NET using Dataset

XML is a tag based language, that means the document is made up of XML tags that contain information. We can create an XML file in several ways.

In the previous section we create an XML file using XmlTextWriter Class. Here we are creating an XML file Product.XML using an ADO.NET Dataset. For that we have to manually create a Datatable first and add the data of Product.XML in the Datatable . Then add the Datatable in a Dataset . Call the method WriteXml of Dataset and pass the file name Product.XML as argument.


         VB.NET Source Code Download           Print Source Code
         How to create an XML file in VB.NET using Dataset - Download
        
VB.Net Tutorial

Imports System.Xml
Imports System.Data

Public Class Form1
    Dim dt As DataTable
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        dt = New DataTable()
        dt.Columns.Add(New DataColumn("Product_ID", Type.GetType("System.Int32")))
        dt.Columns.Add(New DataColumn("Product_Name", Type.GetType("System.String")))
        dt.Columns.Add(New DataColumn("product_Price", Type.GetType("System.Int32")))
        fillRows(1, "product1", 1111)
        fillRows(2, "product2", 2222)
        fillRows(3, "product3", 3333)
        fillRows(4, "product4", 4444)
        ds.Tables.Add(dt)
        ds.Tables(0).TableName = "product"
        ds.WriteXml("Product.xml")
        MsgBox("Done")
    End Sub

    Private Sub fillRows(ByVal pID As Integer, ByVal pName As String, ByVal pPrice As Integer)
        Dim dr As DataRow
        dr = dt.NewRow()
        dr("Product_ID") = pID
        dr("Product_Name") = pName
        dr("product_Price") = pPrice
        dt.Rows.Add(dr)
    End Sub
End Class
		

VB.NET XML Related Contents
*     How to XML in VB.NET
*     How to create an XML file in VB.NET
*     How to open and read an XML file in VB.NET
*     How to open and read an XML file in VB.NET using Dataset
*     How to create an XML file from SQL in VB.NET
*     How to search in an XML file
*     How to filter data in an XML file
*     How to insert data from xml to database
*     How to create an Excel file from XML
*     How to create an XML file from Excel
*     How to xml to DataGridView
*     How to create a TreevView from XML
*     How to create Crystal Reports from XML
*     How to serialization in xml
*     How to serialize a .Net Object to XML
*     How to serialize from an XML file to .Net Object

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved