Pitney Bowes MapXtreme User Manual

Page 173

Advertising
background image

Chapter 8: Working with Data

Table Metadata (TableInfo)

MapXtreme v7.1

180

Developer Guide

it is important to get the string length correct. The DataColumn has a MaxLength property that
should be set to indicate the maximum length string the column could hold. If not set, this value
defaults to -1 in which case the value of 254 is used. Before checking the MaxLength property, the
Catalog looks to see if the DataColumn has a property defined in its ExtendedProperties collection
with the name “StringWidth”. If found, the value for this property is used as the column's width.

This example illustrates how to create a MapInfo Table whose data is stored in a DataTable.

VB example:

Public Shared Sub MapInfo_Data_TableInfoAdoNet(ByVal connection As _

MIConnection)

' Create a new DataTable.
Dim dt As DataTable = New DataTable("CityData")
Dim dc As DataColumn
dc = dt.Columns.Add("City", Type.GetType("string"))
dc.MaxLength = 30
dc = dt.Columns.Add("Country", Type.GetType("string"))
dc.MaxLength = 30
dc = dt.Columns.Add("Continent", Type.GetType("string"))
dc.MaxLength = 30
dc = dt.Columns.Add("Population", Type.GetType("string"))

' Populate the DataTable...

dt.Rows.Add(New Object() {"Madrid", "Spain", "Europe", 1500000})
dt.Rows.Add(New Object() {"Stockholm", "Sweden", "Europe". 985000})

' Now open a MapInfo Table which accesses this DataTable

Dim ti As TableInfoAdoNet = New TableInfoAdoNet("Cities")
ti.ReadOnly = False
ti.DataTable = dt

Dim table As Table = connection.Catalog.OpenTable(ti)

End Sub

Saving and Restoring ADO.NET objects

Saving and Restoring ADO.NET tables can be accomplished in MapXtreme by using the steps
outlined below. Explicit serialization/deserialization of ADO.NET tables is not supported due to
limitations on restoring the underlying System.Data.DataTable. An ADO.NET table is a table in the
Catalog which was created using a MapInfo.Data.TableInfoAdoNet object.

The proper method of serializing/deserializing the ADO.NET based MapInfo table is in the
SaveState method. Serialize all tables that reference the ADO.NET table (i.e., ViewTables or joins)
and then close the ADO.NET table. In the RestoreState method, re-create the ADO.NET MapInfo
table with the same name and then deserialize any dependent MapInfo tables. Order is important
because you have to create the ADO.NET table prior to restoring any other tables.

In the context of a MapXtreme Web Application which implements manual state management, follow
these steps to save and restore an ADO.NET table between client requests.

L

The steps outlined below refer specifically to ADO.NET tables created from a DataTable.

Advertising