vba 即使我在 ADO 的第一个位置有填充的记录集,EOF 也会返回 true
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18743553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EOF returns true even if i have a populated recordset at the first pos in ADO
提问by SomeRandomName
Im trying to get rows from the columns in a recordset and then insert those in a table plain and simple.
我试图从记录集中的列中获取行,然后将这些行简单而简单地插入到表中。
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..
记录集已填充,我使用 .MoveFirst 在 rs 的开头开始,但我仍然在一开始就得到 EOF 真,它跳出 do while ..
I have a similar function woorking but this one won't woork for some reason.
我有一个类似的功能工作,但由于某种原因这个功能不会工作。
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
It jumps out at Do While Not rsData.EOF..
它跳出在 Do While Not rsData.EOF..
采纳答案by HansUp
GetString
leaves the recordset at EOF
. MoveFirst
again before Do While Not rsData.EOF
GetString
将记录集保留在EOF
。 MoveFirst
再之前Do While Not rsData.EOF
rsData.MoveFirst
MsgBox rsData.GetString
rsData.MoveFirst ' <-- add this
'Manipulate each row of the result column.
Do While Not rsData.EOF
回答by Trace
I didn't try your code, but this logically means that the recordset is empty. Check carefully if the query you executed on the db is correct.
我没有尝试你的代码,但这在逻辑上意味着记录集是空的。仔细检查您在数据库上执行的查询是否正确。
In Access, use DAO instead of ADO and try this:
在 Access 中,使用 DAO 而不是 ADO 并尝试以下操作:
Set db = CurrentDb
set rsData = db.OpenRecordset("SELECT Forhandler, Selger FROM data", dbOpenDynaset)