通过ADO中的填充记录集迭代。 [英] Iterating trough a populated recordset in ADO.
本文介绍了通过ADO中的填充记录集迭代。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从记录集中的2列获取行,然后在表中输入行。
记录集已填充并且我使用.MoveFirst从在rs的开头,我仍然在开始的时候得到了EOF,并且它跳出了do ..
我无法弄清楚为什么......或者如何解决这个问题。欢迎Anny见证!
当前代码〜
Im trying to get rows from 2 columns in a recordset and then inser those in a table.
The recordset is populated and i used .MoveFirst to start at the beginning of the rs, Still i get EOF true at the very start and it jumps out of the do while..
I can't figureout why... or how to fix this. Anny insight is welcome!
current Code ~
Public Function makeSäljare()
'Create rs
Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
Dim sql As String
'Select what should be included in the rs.
rsData.Open "SELECT Forhandler, Selger FROM data", _
CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rsData.MoveFirst
MsgBox rsData.GetString
'Manipulate each row of the result column.
Do While Not rsData.EOF
sql = "INSERT INTO säljare (Partner_Namn, Namn ) VALUES ('" & rsData!forhandler & "','" & rsData!Selger & "');"
MsgBox sql
'DoCmd.SetWarnings (False)
DoCmd.RunSQL (sql)
'DoCmd.SetWarnings (True)
rsData.MoveNext
'If rsData.EOF Then Exit Do
Loop
rsData.Close
End Function
推荐答案
看看这里:
BOF,EOF属性(ADO) [ ^ ]
使用VBA Recordset对象时要避免的10+错误 [ ^ ]
VBA陷阱:使用记录集 [ ^ ]
Open Method(ADO Recordset) [ ^ ]
如何打开ADO连接和记录集对象 [ ^ ]
ADO编程代码示例 [ ^ ]
如何在ADO中正确打开记录集 [ ^ ]
Have a look here:
BOF, EOF Properties (ADO)[^]
10+ mistakes to avoid when using VBA Recordset objects[^]
VBA Traps: Working with Recordsets[^]
Open Method (ADO Recordset)[^]
How To Open ADO Connection and Recordset Objects[^]
ADO Programming Code Examples[^]
How to Properly Open a Recordset in ADO[^]
我使用.getString方法_after_我使用.MoveFirst导致.getString方法将rs移动到EOF而不是因为它而循环到rs!
I was using the .getString method _after_ i used .MoveFirst leading to the .getString method moving the rs to EOF and not looping trough the rs because of it!
这篇关于通过ADO中的填充记录集迭代。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文