zoom to extent

Topics: SharpMap v2.0
Oct 17, 2007 at 6:40 AM
i have return the code for rendering
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Election/election.mdb";
string tablename = "S01_AC"; //Name of table in database
string oid = "PERIMETER"; //Name of object ID column - MUST be integer!
string xColumn = "0.108"; //Name of X coordinate column - MUST be double!
string yColumn = "0.153"; //Name of Y coordinate column - MUST be double!

myMap = helper.InitializeMap(new System.Drawing.Size(600,500));
SharpMap.Layers.VectorLayer layS01AC = new SharpMap.Layers.VectorLayer("S01AC"); //Create layer
layS01_AC.DataSource = new OleDbPoint(connStr, tablename, oid, xColumn, yColumn); //Set the datasource to the database
myMap.Layers.Add(layS01_AC); //Add layer to map
myMap.ZoomToExtents(); //Zoom to extents
System.Drawing.Image img = myMap.GetMap(); //Render map

but it is displaying error as "Specified cast is not valid." near zoomtoextents line
plz correct my code.
Coordinator
Oct 18, 2007 at 7:59 AM
I think you need to have layS01_AC.DataSource.Open() in there somewhere. Probably before the call to ZoomToExtents.

I don't exactly know since I've never used the OleDbPoint provider, even though the source code is available for download. I could even load the PDB symbols and debug it, and trap the exception on the exact line that it fails to find out why it's failing. I wonder why I don't do that...
Coordinator
Oct 18, 2007 at 9:04 AM
Oh, and...

string xColumn = "0.108"; //Name of X coordinate column - MUST be double!
string yColumn = "0.153"; //Name of Y coordinate column - MUST be double!

Those need to be column names.