EOF returns true even if I have a populated record set in the first pos in ADO

I am trying to get rows from columns in a recordset and then inserting them into a table is simple and simple.

The entries are full, and I used .MoveFirst to start at the beginning of rs. However, I get EOF true at the very beginning, and it jumps out of do while.

I have a similar woorking function, but this one for some reason will not look.

I can’t understand why ... or how to fix it. 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

He jumps into Do While Not rsData.EOF ..

+3
source share
2 answers

GetStringleaves the recordset in EOF. MoveFirstagain beforeDo 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
+3
source

, , . , , db.

Access DAO ADO :

Set db = CurrentDb
set rsData = db.OpenRecordset("SELECT Forhandler, Selger FROM data", dbOpenDynaset) 
0

Source: https://habr.com/ru/post/1695013/


All Articles