Office Systems Blog

Joao Livio 2002 - 2008 Portugal

August 2006 - Posts

Export a Table From Office 2007 Beta 2 as XML and Read it in Visual Studio whit a DataSet

Please do not forget at the time this post OFFICE 2007 is still in STAGE BETA.

My intention with this post is to provide a quick workaround to the issue 

For this Article you can download free the bellow Tools

Visual Studio Express edition

http://msdn.microsoft.com/vstudio/express/

Office 2007 Beta 2

http://www.microsoft.com/office/preview/beta/download/en/default.mspx

INTRODUCTION
In this section we are going to see as to export of the Access 2007 Beta 2 the Table Customers to XML and to import the same one in the same format without SCHEMA, Pure XML to a DATASET into Visual Studio. I am going to use the Visual Studio 2005 Professional provided for the MSDN that is exacly for test proposes. I go to export the filing-cabinet to XML, chose the Customers Table of the Database NORTHWIND of  Microsoft, I go to choose PROVIDER XML with the Right Button of the mouse, as it is I demonstrate in (Figure 1)
Figure 1
We go to choose the place for writing of our filing-cabinets. You do not modify the name of file XML as demonstrated in Figure 2 because it goes to be used bellow with the name for Default.
Figure 2
You select the options that you want, in this in case that I am going to include the SCHEMA (Figure 3), filing-cabinet XSD and Filing-cabinet XML, but I do not go to need of filing-cabinet XSD. The same would be useful for a detailed use of the ROWS in way of structure of the Table, but in this in case that we only go to need the data exactly.

Figure 3

Now You open the Visual Studio .NET 2005 and create a new Application Windows Form, gives to a name any (Figure 4)

Figure 4

After your Application is created(Figure 5) you go to execute two operations

1. you insert a CommandButton1 in the Form1 and Handle CLICK and place the code in low.

2. IT PASSES FILING-CABINET XML for its folder MY DOCUMENTS because i formated the code to read it there

Figure 5

CODE

VB

Imports System

Imports System.Data

Dim myDocumentsFolder As String
myDocumentsFolder = _
System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim DataSet1 As New DataSet
DataSet1.ReadXml(myDocumentsFolder & "\Customers.xml")

MessageBox.Show(DataSet1.Tables(1).Rows.Count.ToString)

C#

using System

using System.Data

string myDocumentsFolder;
myDocumentsFolder = _
System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
DataSet DataSet1 = new DataSet();
DataSet1.ReadXml(myDocumentsFolder + "\\Customers.xml");


MessageBox.Show(DataSet1.Tables(1).Rows.Count.ToString);

It copies then the code for the Handle Click of the CommandButton1 and runs the Application in RELEASE cliking in F5 and and the Button. The waited result is two distinct tables as bellow I explain reason after. As demonstrated in (Figure 6), it returned of 91 Rows (91 lines) of Information. I am reading Table(1) because Table(0) it has the relation for the table for which the Customers Table is related in.

 

Figure 6

To prove that we are to speak exacly of the same information and for foils, I place the line number (Figure 7) removed of a Print Screen of the Customers Table here in Access 2007.

HOPE THAT HELPES

Agosto/2005

Joao Livio

Microsoft Office Systems MVP

http://officept.mvps.org