阅读:1876回复:4
请各位帮我看看这段关联代码!<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> |
|
1楼#
发布于:2004-06-09 13:47
<P>这只是其中一段吧?好象是关联部分的错误,数据库是什么格式的?</P>
|
|
|
2楼#
发布于:2004-06-09 16:28
数据库是dbf 图层是shape格式
|
|
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> |
|
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" />
|
|
|