I’m having an issue getting a SQL Layer to save to a Tab File, but keep getting an error with the columns or the call to save the tab file just closes the app, The SQL Table is just a table created using MapInfo 11. I’m new to thinkgeo. Anyone got any pointers?
error: A first chance exception of type ‘System.ArgumentException’ occurred in mscorlib.dll: Destination array was not long enough. Check destIndex and length, and the array’s lower bounds.
Code:
static void CreateTabFROMSQL()
{
string connectString = “Data Source=localhost\SQL2012;Initial Catalog=AGDAT_FARMMAP_AGTRIX;Persist Security Info=True;Integrated Security=True;”;
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, “T_FARM_CUR”, “MI_PRINX”);
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
sql2008Layer.Open();
var columns = ViewToTabColumns(sql2008Layer.FeatureSource.GetColumns().ToList(), “MI_PRINX”);
var bbox = sql2008Layer.FeatureSource.GetBoundingBox();
var features = sql2008Layer.FeatureSource.GetFeaturesInsideBoundingBox(bbox, ReturningColumnsType.AllColumns );
TabFeatureSource.CreateTabFile(@".\MyTab1.TAB", columns, features);
TabFeatureLayer.BuildIndexFile(@".\MyTab1.TAB", BuildIndexMode.Rebuild);
Console.WriteLine(“complete”);
Console.ReadLine();
}
static List<TabDbfColumn> ViewToTabColumns(List<FeatureSourceColumn> fscs, string IDField)
{
List<TabDbfColumn> columns = new List<TabDbfColumn>();
foreach(var fsc in fscs)
{
Console.WriteLine(fsc.TypeName);
// if (TypetoColumnType(fsc.TypeName) != DbfColumnType.Null && fsc.ColumnName != IDField)
columns.Add(new TabDbfColumn(fsc.ColumnName, TypetoColumnType(fsc), fsc.MaxLength, TypetoDecmial(fsc), true, true));
}
return columns;
}
static DbfColumnType TypetoColumnType(FeatureSourceColumn col)
{
switch(col.TypeName)
{
//case “Logical”: return DbfColumnType.Logical;
//case “Memo”: return DbfColumnType.Memo ;
case “Date”: return DbfColumnType.Date;
case “DateTime”: return DbfColumnType.DateTime;
case “Int16”: return DbfColumnType.IntegerInBinary;
case “Int32”: return DbfColumnType.IntegerInBinary;
case “Double”: return DbfColumnType.DoubleInBinary;
case “String”: return DbfColumnType.Character;
case “Guid”: return DbfColumnType.Character;
case “Float”: return DbfColumnType.Float;
case “Decimal”: return DbfColumnType.Float;
case “Numeric”: return DbfColumnType.Numeric;
//Geometry
}
return DbfColumnType.Null;
}
static int TypetoDecmial(FeatureSourceColumn col)
{
switch (col.TypeName)
{
case “Double”: return 6;
case “Float”: return 6;
case “Decimal”: return 6;
case “Numeric”: return 6;
}
return 0;
}