PDA

View Full Version : In-memory dataset?



markmpf
07-20-2010, 12:55 PM
Hello,

I want to display data for each state with the MapPoint ActiveX control.

Is it possible to programatically create a dataset without importing or linking data, and then programatically insert records in this "in-memory" dataset?

Thanks,

Mark

P.S. please try to answer the question if you know about it (i.e., please don't ask "what are you trying to do?")

markmpf
07-20-2010, 02:55 PM
The closer I came to achieve this is by using a pushpin dataset. However, when I call DisplayDataMap, I receive the errors:

'Invalid procedure call or argument'

or

'Parameter Is Incorrect'

I am including the code below. Any help on this will be appreciated

I suspect that the pushpins only have string data while the method requires at least one numeric field. However, I do not know how to create a field specification for the MapPoint.DataSet

Thanks



Private Sub MapDataArray()
Dim objLoc As MapPoint.Location
Dim objMap As MapPoint.Map
Dim objPushpin As MapPoint.Pushpin
Dim objDataset As MapPoint.DataSet
Dim objDatamap As MapPoint.DataMap
Dim blnResult As Boolean

i = 0

Dim MyArray(50) As Single
'populate array with values
' MyArray = getValues()
'

If ubound(MyArray) - lbound(MyArray) > 0 Then
Set objMap = objMapCtrl.ActiveMap

Set objDataset = objMap.DataSets.AddPushpinSet("MyData")

'Place a pushpin on the map for each selected property
For i=ubound(MyArray) To lbound(MyArray)

Set objLoc = objMap.FindPlaceResults(StateNames(i) & ", United States")(1)

Set objPushpin = objMap.AddPushpin(objLoc, MyArray(i))
objPushpin.Note = MyArray(i)
blnResult = objPushpin.MoveTo(objDataset)
Next i

objDataset.DisplayDataMap

'Using the following instead has the same problem
' objDataset.DisplayDataMap(DataMapType:=MapPoint.Ge oDataMapType.geoDataMapTypeShadedArea, _
' ShowDataBy:=MapPoint.GeoShowDataBy.geoShowByRegion 1, _
' CombineDataBy:=MapPoint.GeoCombineDataBy.geoCombin eByNone, _
' DataRangeType:=MapPoint.GeoDataRangeType.geoRangeT ypeDefault, _
' DataRangeOrder:=MapPoint.GeoDataRangeOrder.geoRang eOrderDefault, _
' ColorScheme:=2)
Else
strMsg = "No data to plot!"
MsgBox strMsg, vbOKOnly + vbExclamation, "Map"
End If
End Sub

Mattys Consulting
07-20-2010, 09:28 PM
MapPoints methods are very controlled to prevent you from doing this.
Essentially you are trying to write to a locked Jet database.
You have to use the .ImportData method supplied to you.

CMJ
08-12-2010, 04:49 PM
The following code will programatically create a dataset without importing or linking data, and then programatically insert records in this "in-memory" dataset which is what you want to do. You should note this is VB.net and the dataset is an OLEDB dataset and not a MapPoint dataset. This has the added advantage of being able to update a connected database whereas a mappoint dataset will not update a connected database . Hope this helps you.



Imports System.Data.OleDb

Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim idCoulumn As DataColumn
Dim nameCoulumn As DataColumn
Dim i As Integer
dt = New DataTable()
idCoulumn = New DataColumn("ID", Type.GetType("System.Int32"))
nameCoulumn = New DataColumn("Name", Type.GetType("System.String"))
dt.Columns.Add(idCoulumn)
dt.Columns.Add(nameCoulumn)
dr = dt.NewRow()
dr("ID") = 1
dr("Name") = "Name1"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr("ID") = 2
dr("Name") = "Name2"
dt.Rows.Add(dr)
ds.Tables.Add(dt)
For i = 0 To ds.Tables(0).Rows.Count - 1
MsgBox(ds.Tables(0).Rows(i).Item(0) & " -- " & ds.Tables(0).Rows(i).Item(1))
Next i
idCoulumn.Dispose()
nameCoulumn.Dispose()