数据绑定

1.数据绑定

Private Sub mnuLinkdata_Click()
'*************************连接数据库*******************
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "driver=sql server;server=127.0.0.1;uid=sa;pwd=jsly;database=jsly"
conn.Open

Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandText = "select * from tunnel"

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set rs = cmd.Execute
'*************************连接数据库*******************

'****************************绑定数据*******************
Dim ds As Dataset
Set ds = Map1.DataSets.Add(miDataSetADO, rs, "ds", "ID", , "点管道")
'DataSets.Add  Type, SourceData, [Name], [Geofield], [SecondaryGeofield], [BindLayer], [Fields], [Dynamic]
MsgBox "绑定成功!"
'****************************绑定数据*******************
mnuLinkdata.Enabled = False

End Sub

 

2.获取图元对应数据库信息

Private Sub Map1_DblClick()


'2、获取图元信息
Dim Layer As MapXLib.Layer
Dim ds As MapXLib.Dataset
Dim fields As MapXLib.fields
Dim ftr As MapXLib.Feature

Set ds = Map1.DataSets("ds")
Set Layer = ds.Layer

Set fields = ds.fields

For Each ftr In Layer.Selection
 'MsgBox Layer.AllFeatures.Item(ftr.FeatureKey).Name
 frmShowData.Label1.Caption = fields.Item(2) & ": " & ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(2))
 frmShowData.Label2.Caption = fields.Item(3) & ": " & ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(3))
 frmShowData.Label3.Caption = fields.Item(4) & ": " & ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(4))
 frmShowData.Label4.Caption = fields.Item(5) & ": " & ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(5))
 frmShowData.Label5.Caption = fields.Item(6) & ": " & ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(6))
Next

 

frmShowData.Show
End Sub

 

3.开始数据监测,数据库表的第二个字段大于5的图元style变化

Private Sub Command1_Click()
 Timer1.Enabled = True
 Timer1.Interval = 1000
End Sub

 

 

 

 

Private Sub Timer1_Timer()

Dim Layer As MapXLib.Layer
Dim ds As MapXLib.Dataset
Dim fields As MapXLib.fields
Dim ftr As MapXLib.Feature
'Dim Oldsytle As MapXLib.Style

Set ds = Map1.DataSets("ds")
Set Layer = ds.Layer

Set fields = ds.fields

For Each ftr In Layer.AllFeatures
 'MsgBox Layer.AllFeatures.Item(ftr.FeatureKey).Name  用来确定图元(行)
 'MsgBox fields.Item(2)                               用来确定字段(列)
 If ds.Value(Layer.AllFeatures.Item(ftr.FeatureKey).Name, fields.Item(2)) > 5 And ftr.Style.SymbolBitmapSize = 24 Then
    ftr.Style.SymbolBitmapSize = 30
    ftr.Update
 Else
    ftr.Style.SymbolBitmapSize = 24
    ftr.Update
 End If

Next

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值