hmcheung
Jun 12th, 2000, 04:27 PM
Hi,
I'm using VB6. I used the following code to connect to a foxpro dbf using ADO. I've added a new column "Status" to it using SQL, and the initial value of the whole column is .NULL. . I tried to update this column row by row but I failed. It turns out that I get an error. I found out that when I do the first update the whole column (rather than only one cell) is updated. So when it comes to the 2nd update, an error occurs because the cursor is already at the bottom and can't movenext anymore.
so how can I make it so that it won't update the whole column at one time? thank you very much.
the code:
-----------------------------------------------------------
Private Sub cmdUpdateDBF_Click()
Dim m As Integer 'for looping
Set cnMain = New ADODB.Connection
strconnect = "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBF; SourceDB=" & path_name
cnMain.Open strconnect
cnMain.Execute "alter table " & table_name & " add column Status char(20)"
Set rsMain = New ADODB.Recordset
rsMain.Open "select " & "Status" & " from " & arrayDBFPath(1), cnMain, adOpenStatic, adLockOptimistic
rsMain.MoveFirst
rsMain("Status")= "status A"
rsMain.Update '1st update
rsMain.MoveNext
rsMain("Status")= "status B"
rsMain.Update '2nd update
rsMain.MoveNext
rsMain("Status")= "status C"
rsMain.Update '3rd update
end sub
I'm using VB6. I used the following code to connect to a foxpro dbf using ADO. I've added a new column "Status" to it using SQL, and the initial value of the whole column is .NULL. . I tried to update this column row by row but I failed. It turns out that I get an error. I found out that when I do the first update the whole column (rather than only one cell) is updated. So when it comes to the 2nd update, an error occurs because the cursor is already at the bottom and can't movenext anymore.
so how can I make it so that it won't update the whole column at one time? thank you very much.
the code:
-----------------------------------------------------------
Private Sub cmdUpdateDBF_Click()
Dim m As Integer 'for looping
Set cnMain = New ADODB.Connection
strconnect = "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBF; SourceDB=" & path_name
cnMain.Open strconnect
cnMain.Execute "alter table " & table_name & " add column Status char(20)"
Set rsMain = New ADODB.Recordset
rsMain.Open "select " & "Status" & " from " & arrayDBFPath(1), cnMain, adOpenStatic, adLockOptimistic
rsMain.MoveFirst
rsMain("Status")= "status A"
rsMain.Update '1st update
rsMain.MoveNext
rsMain("Status")= "status B"
rsMain.Update '2nd update
rsMain.MoveNext
rsMain("Status")= "status C"
rsMain.Update '3rd update
end sub