阅读:1238回复:0
Example in Visual Basic
Private Sub Command1_Click()
Dim lif As MapXLib.LayerInfo Dim lyr As Layer Dim ds As Dataset Dim nRows As Integer Dim nFeatures As Integer Dim I As Integer Dim rv As RowValues Dim ftr As Feature Dim ftrs As Features ' Create a new layer from a remote database Set lif = CreateObject("MapX.LayerInfo.4") lif.AddParameter "name", "States" lif.Type = miLayerInfoTypeServer lif.AddParameter "Query", "Select * from MAPX.USA" lif.AddParameter "ToolKit", "ORAINET" lif.AddParameter "ConnectString", "SRVR=cygnus;UID=mapx;PWD=mapx" Set lyr = Map1.Layers.Add(lif, 1) ' Add a dataset on the layer Set ds = Map1.Datasets.Add(miDataSetLayer, lyr) ' Let's determine the number of rows in the dataset. nRows = ds.RowCount ' This returns Zero - do not use. ' A simple way to determine the number of rows in a dataset ' is to use the number of features. A dataset contains one ' row for each feature in the layer. nRows = ds.Layer.AllFeatures.Count ' The number of features ' This is a more robust method for determining the number of rows. ' Since all datasets have one row per feature and we are most likely ' trying to determine the number of rows so we can iterate through ' the dataset, it is best to use the feature itself or the ' feature's key to retrieve a RowValues collection. ' Note that AllFeatures on a remote table causes a full scan of ' the table and may be slow. Therefore, we do not use syntax ' like: ' For I = 1 To ds.Layer.AllFeatures.Count ' as this will performa full scan every time through the loop. ' This is the reason why the RowCount method returns Zero for ' a remote table. I = 0 Set ftrs = ds.Layer.AllFeatures For Each ftr In ftrs Set rv = ds.RowValues(ftr) I = I + 1 Next nRows = I ' Display the number of rows found in the table MsgBox " There are " & nRows & " rows." & Chr(13) & " There are " & ftrs.Count & " features." End Sub |
|
|