Pitney Bowes MapXtreme User Manual
Page 175

Chapter 8: Working with Data
Table Metadata (TableInfo)
MapXtreme v7.1
182
Developer Guide
has no ability to modify the IDbCommand object to fetch a specific record. Thus, a second
IDbCommand object must be supplied for this purpose. The “FetchByKey” IDbCommand object
must meet the following requirements:
•
When ExecuteReader is called on this command object, it must produce a data reader that has
the same columns as the sequential command object and in the same order.
•
The FetchByKeyCommand must contain a Parameters collection and must contain one
parameter for each member of the key. For example, if the TableInfo.KeyColumns specifies a
key as consisting of the “city” and “state” columns, then the FetchByKeyCommand must contain
two parameter objects. The first parameter object is assigned a value representing the first
column specified in the TableInfo.KeyColumns collection (e.g., a value for “city”), the second
parameter object is assigned a value representing the second column specified in the
TableInfo.KeyColumns collection (e.g., a value for “state”), and so on. When ExecuteReader is
called on the FetchByKeyCommand, the reader must return the record which represent s the
specified key.
This example illustrates how to create a MapInfo Table that accesses data through the ADO.NET
connected command objects.
VB example:
Public Shared Sub MapInfo_Data_TableInfoAdoNet2(ByVal connection _
As MIConnection)
Dim ti As TableInfoAdoNet = New TableInfoAdoNet("EuropeanCities")
Dim _conn As OleDbConnection = New _
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data _
Source=C:\Data\EuropeCities.mdb")
Dim selectQuery As String = "SELECT City, Country, Continent, _
Pop_1994 FROM EuropeCities"
Dim _OleDbCommand As OleDbCommand = New OleDbCommand(selectQuery)
_OleDbCommand.Connection = _conn
selectQuery = selectQuery + " where City = @City AND _
Country = @Country"
Dim _OleDbKeyCommand As OleDbCommand = New _
OleDbCommand(selectQuery)
_OleDbKeyCommand.Parameters.Add("@City", OleDbType.Char)
_OleDbKeyCommand.Parameters.Add("@Country", OleDbType.Char)
_OleDbKeyCommand.Connection = _conn
' The MapInfo Table will Open/Close the connection as necessary.
' If this is expensive the application could open the connection
' before opening the table and closing the connection after the
' table is closed.
ti.SequentialCommand = _OleDbCommand
ti.FetchByKeyCommand = _OleDbKeyCommand
' Tell the table which column(s) constitute a key - for this table
' it is acompound key consisting of values from the City and County
' columns.
Dim sc As StringCollection = New StringCollection
sc.Add("City")
sc.Add("Country")