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>="1.0"="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
dsCustList = New DataSet
dsCustList.ReadXml(m_connCustomers)
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.