Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / Visual Basic
Article

Purpose is to demonstrate using xml as a file type database

Rate me:
Please Sign up or sign in to vote.
2.42/5 (19 votes)
24 Sep 20032 min read 65.5K   631   37   2
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:

XML
<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.

VB.NET
'...
 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:

VB.NET
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


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generaloptions.xml Pin
Vitoto12-Apr-05 10:40
Vitoto12-Apr-05 10:40 
GeneralRe: options.xml Pin
TLWallace16-Apr-05 3:41
TLWallace16-Apr-05 3:41 

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

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