songrose
路人甲
路人甲
  • 注册日期2004-06-07
  • 发帖数18
  • QQ
  • 铜币191枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1723回复:4

请各位帮我看看这段关联代码!

楼主#
更多 发布于:2004-06-08 23:38

<P>Private Sub Command1_Click()</P>
<P>tofield = List1.Text
fromfield = List2.Text
Dim col As ColumnHeader
Set col = ListView1.ColumnHeaders.Add(, , "记录数")
Dim i As Integer
Dim items As ListItem
Dim nFields As Integer
dim ntable as new mapobjects2.table
 If lyr.AddRelate(tofield, ntable, fromfield, True) Then
   For Each fld In lyr.Records.Fields
      Set col = ListView1.ColumnHeaders.Add(, , fld.Name)
   Next
     Set recs = lyr.Records
     Do While Not recs.EOF
     nFields = 1
       i = i + 1
    set items = ListView1.ListItems.Add(, , "No." ; i)
        For Each fld In recs.Fields
        items.SubItems(nFields) = fld.ValueAsString
         nFields = nFields + 1
        Next
       recs.MoveNext
     Loop
     Else
   MsgBox "不能建立关联", vbInformation
 End If</P>
<P>exit sub
 End Sub</P>
<P>为什么运行的时候总是出现提示“实时错误 ‘-2147417848(80010108)‘自动化错误”</P>
<P>请大家帮忙看看,谢谢了!</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-06-09 13:47
<P>这只是其中一段吧?好象是关联部分的错误,数据库是什么格式的?</P>
举报 回复(0) 喜欢(0)     评分
songrose
路人甲
路人甲
  • 注册日期2004-06-07
  • 发帖数18
  • QQ
  • 铜币191枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-06-09 16:28
数据库是dbf  图层是shape格式
举报 回复(0) 喜欢(0)     评分
djcheng2003
路人甲
路人甲
  • 注册日期2003-08-11
  • 发帖数260
  • QQ
  • 铜币596枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-06-09 20:05
<P>看看我的啊 我也是和你的方法差不多,可就是关联不上 我快晕了</P><P>Private Sub Command1_Click()
  Dim fName As String, dName As String
  CommonDialog1.Filter = "dBASE files (*.dbf)|*.dbf"
  CommonDialog1.ShowOpen
  '
  ' Connect to the DBF using DAO.
  '
  If CommonDialog1.fileName <> "" And List1.ListIndex > -1 Then
    Dim pTable As New MapObjects2.Table
    pTable.Database = "dBase IV;DATABASE=" ; Left(CommonDialog1.fileName, Len(CommonDialog1.fileName) - Len(CommonDialog1.FileTitle) - 1)</P><P>    pTable.Name = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)
  
    Dim pLayer As MapObjects2.MapLayer, pFName As String, i As Integer
    Set pLayer = MapRelate.Layers(0)
    pFName = List1.List(List1.ListIndex)
    '
    ' First, check that the selected Field also appears in the Table.
    '
    For i = 0 To pTable.Records.TableDesc.FieldCount - 1
      If pTable.Records.TableDesc.FieldName(i) = pFName Then
        '
        ' Set cache size.</P><P>        '
        pTable.MaxCachedRelateRecords = CLng(Text1.text)
        '
        ' Now perform the relate to the selected Field.
        '
        If pLayer.AddRelate(pFName, pTable, pFName, True) Then
          ListLayers
        Else
          MsgBox "Failed Relate"
        End If
      End If
    Next i
  Else
    MsgBox "Please select a Field from the list, and a file, and try again."
  End If
End Sub</P>
举报 回复(0) 喜欢(0)     评分
heqjxiaoyao
路人甲
路人甲
  • 注册日期2003-07-31
  • 发帖数981
  • QQ83031582
  • 铜币910枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-06-10 16:24
<P>哦,关联不是很难的阿</P><P>而且可以通过多种方式对好几种数据库进行关联的</P><P>可惜好长时间都没有学习了,我都忘了怎么做了,哈哈</P><img src="images/post/smile/dvbbs/em08.gif" /><img src="images/post/smile/dvbbs/em08.gif" />
希望大家访问我的个人博客: 随笔闲谈: http://rsgisman.bokee.com
举报 回复(0) 喜欢(0)     评分
游客

返回顶部