Global Navigation Bar

MapInfo Products Knowledge Base


Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: All Windows Platforms
Category: Data Access

Summary:
How to add a field to a table that can be updated with any values?

Question:
Using Table.AddColumns to add a temporary column to an open table. Then, this field will be updated with values. In other words, not an expression that uses other column values but some simple values such as 1, 2, 3 ...etc.). The help says to use Table.AddColumns(Columns, BindType) and set the bind type to be Static: "then [temporary] physical columns are added to the table. These columns may be updated with any value the application desires."

After the field is added, the data can no longer be accessed. When creating an MIDataReader on the table and iterating thru the records, its Read property returns false immediately.

Here is the code:

Hide details for C# Code:C# Code:
MapInfo.Data.MIConnection Connection = new MapInfo.Data.MIConnection();

Connection.Open();
MapInfo.Data.TableInfoServer ti = new TableInfoServer("Members");
ti.ConnectString = "DRIVER={SQL Server};SERVER=cimakaro-w1;DATABASE=georgetown;uid=sa;pwd=zackary";
ti.Query = "Select * From tester5";
ti.Toolkit = ServerToolkit.Odbc;

MapInfo.Data.SpatialSchemaXY xy =new SpatialSchemaXY();
xy.CoordSysString = "CoordSys Earth Projection 1, 0";
xy.XColumn = "xcoord";
xy.YColumn = "ycoord";
xy.NullPoint = "0.0, 0.0";
ti.SpatialSchema = xy;

MapInfo.Data.Table tbl = MapInfo.Engine.Session.Current.Catalog.OpenTable(ti);
if( tbl!= null)
{
MapInfo.Data.Columns cols =new MapInfo.Data.Columns();
cols.Add(ColumnFactory.CreateSmallIntColumn("Temp"));
tbl.AddColumns(cols, BindType.Static);

listBox1.Items.Clear();
MIDataReader rdr= tbl.ExecuteReader();
while (rdr.Read())
{
listBox1.Items.Add(rdr.GetValue("xcoord"));
}
rdr.Close();
}

Hide details for VB.NET Code:VB.NET Code:
Dim ti As New TableInfoServer("Members")
ti.ConnectString = "DRIVER={SQL Server};SERVER=test;DATABASE=test"
ti.Query = "Select * From maila"
ti.Toolkit = ServerToolkit.Odbc

Dim xy As New SpatialSchemaXY
xy.CoordSysString = "CoordSys Earth Projection 1, 0"
xy.XColumn = "Longitude"
xy.YColumn = "Latitude"
xy.NullPoint = "0.0, 0.0"
ti.SpatialSchema = xy

Dim tbl As Table = Session.Current.Catalog.OpenTable(ti)
If Not tbl Is Nothing Then
Dim cols As New Columns
cols.Add(ColumnFactory.CreateSmallIntColumn("Temp"))
tbl.AddColumns(cols, BindType.Static)
ListBox1.Items.Clear()
Dim rdr As MIDataReader = tbl.ExecuteReader()
Do While rdr.Read
ListBox1.Items.Add(rdr.GetValue("CARRIER"))
Loop
rdr.Close()
End If



If the AddColumns code is commented out, then the listbox is populated with data (rdr.Read is True until it iterated thru all 1500 records). With the AddColumns code enabled rdr.Read is false on the first try?

Answer:
This looks like an issue with TableInfoServer tables. If the SQL Server table is replaced with just a native TAB file, the program doesn't hang and populates the list box when the tbl.AddColumns isn't commented out.

AddColumns is not supported in the following table types: Server, View, Seamless, AdoNet, ResultSet, or Drilldown.


Last Modified:
Global Navigation Bar