Click here to Skip to main content
Licence 
First Posted 5 Sep 2003
Views 55,141
Bookmarked 37 times

Purpose is to demonstrate using xml as a file type database

By | 24 Sep 2003 | Article
The example project in VB.NET 2003 contains a mixture of programming topics for VB.NET.

Sample Image - OrderAutomation.gif

Introduction

In this article I try to cover at least four basic and fundamental programming aspects of VB.NET

  • Office Automation - VBA
  • Microsoft Agent Programming
  • XML Input/Output
  • Microsoft Excel worksheet

Implementation

OrderAutomation demonstrates one of the most basic and practical uses of XML today. Data comes in all shapes and sizes and media, getting this data from one source and transferred over to a totally new and different source has been a bit trite in the past. The beauty of XML is that the same software can process all of this diversity. Whatever you can do with one kind of data you can do with all the others.

Here we have a typical xml file:

<P><?xml version="1.0" 
encoding="UTF-8"?>
<Supplier-List>
<Suppliers>
    <SupplierID>1</SupplierID>
    <CompanyName>Exotic Liquids</CompanyName>
    <ContactName>Charlotte Cooper</ContactName>
    <ContactTitle>Purchasing Manager</ContactTitle>
    <Address>49 Gilbert St.</Address></P>
<P>    <City>London</City>
    <PostalCode>EC1 4SD</PostalCode>
    <Country>UK</Country></P>
<P>    <Phone>(171) 555-2222</Phone>
</Suppliers>
 ....
</Supplier-List></P>

Getting data from an XML File is easy, and working with data is easier than ever with Xml. If you want the results from xml as a forward only, read-only stream of data, you can execute a command and retrieve the results using the DataReader.

For more interactive operations such as binding to, navigating through, or remoting the results of a xml query, you can place the results in a DataSet as shown in this example.

'...
 Dim dsNewRec as New Dataset
dsnewRec.ReadXml("suppliers.xml")
            newRow = dsNewRec.Tables(0).NewRow()
            foundrow = dsProdList.Tables(0).NewRow()

            For iCusts = 0 To lstCustomers.CheckedItems.Count - 1
             ....
            Next iCusts

            dsNewRec.AcceptChanges()
            ShowInvoice()
'...

High Points

The most important concept to remember is that the DataSet is a data structure separate and distinct from a data store. Although you get data from an xml file in this example, it doesn't matter where the data comes from; the DataSet will always present a consistent programming model.

It is a simple collection of data with relational database characteristics. There is no Load, Open, or Execute on a DataSet because it doesn't know where it gets its data from. The following example populates a DataSet with tables:

    Dim i As Integer
      ' Fill a DataSet by loading an XML document with items
       dsCustList = New DataSet
       dsCustList.ReadXml(m_connCustomers) ' Set and bind it to the DataSet.
      For i = 0 To dsCustList.Tables(0).Rows.Count - 1
         With lstCustomers
      .Items.Add(dsCustList.Tables(0).Rows(i)("CompanyName").ToString, False)
           End With
       Next i

Conclusion

What I've tried to demonstrate is using xml as a file type database. XML can be later converted to any type database format you choose (i.e. MS Access, SQL Server, Oracle, others..) It also, uses Microsoft Agent as a helpful assistant during program execution.

The example project in VB.NET 2003 contains a mixture of programing topics for the VB.NET programmer. This was my first attempt to try and understand xml and the new xml technologies using VB.NET. What the example does is it processes inventory, payment invoices, and product supply, and takes that input and dumps it into an excel spreadsheet for calculation.

Read Write XML. This program utilizes the .NET Datagrid, Tab, and Print Preview controls and spell check.

Code comes with some examples provided by Microsoft, PlanetSource, and various other websites.

Enjoy!

Requirements

  • Visual Studio 2003
  • Microsoft Office Standard Edition
  • Microsoft .NET Framework 1.1

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

TLWallace

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaloptions.xml PinmemberVitoto10:40 12 Apr '05  
GeneralRe: options.xml PinmemberTLWallace3:41 16 Apr '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 25 Sep 2003
Article Copyright 2003 by TLWallace
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid