使用VB6和Oracle
将错误视为
“
ora-08103 object no longer exists
”
在下一行
Do While Not MyRs.EOF
代码:
Dim str3 As String
Dim str 4 As String
mADO_Connection.ConnectionTimeout = 15
mADO_Connection.Open "connection string"
Dim MyCmd As ADODB.Command
Set MyCmd = New ADODB.Command
MyCmd.CommandText = "PROC_GET_EMPLOYEE"
MyCmd.CommandType = adCmdStoredProc
Dim MyParam As ADODB.Parameter
Set MyParam = New ADODB.Parameter
MyParam.Name = "DATE"
MyParam.Value = "20150531"
MyParam.Size = 8
MyParam.Direction = adParamInput
MyParam.Type = adVarChar
MyCmd.Parameters.Append MyParam
Dim MyRs As ADODB.Recordset
Set MyRs = New ADODB.Recordset
MyCmd.CommandTimeout = 1000
MyCmd.ActiveConnection = mADO_Connection
MyRs.CursorLocation = adUseClient
MyRs.CacheSize = 100
MyRs.Open MyCmd, , adOpenForwardOnly, adLockReadOnly
If MyRs.Fields.Count > 0 Then
str4 = MyRs.Fields.Count
Do While Not MyRs.EOF
str4 = MyRs.Fields("acct#").Value
For x = 0 To MyRs.Fields.Count - 1
str4 = str4 & MyRs(x) & ","
Next
str4 = Left(str4, Len(str4) - 1)
str4 = str4 & vbCrLf
str3 = str3 & str4
str4 = ""
MyRs.MoveNext
If MyRs.EOF Then Exit Do
Loop
MsgBox "Success"
End If
Set fobj = New FileSystemObject
Set mfile = fobj.CreateTextFile("C:\myfile.csv")
Set mfile = fobj.GetFile("C:\myfile.csv")
Set strm = mfile.OpenAsTextStream(ForWriting)
strm.Write str4
Set strm = Nothing
Set fobj = Nothing
Set mfile = Nothing
End Sub
如何解决这个问题?
答案 0 :(得分:0)
这是一个Oracle错误,只有一个转发Oracle游标。
问题的根本原因与“文件写入”无关。
只需删除那个愚蠢的If MyRs.EOF Then Exit Do
:您已经了解了Do While Not MyRs.EOF
。
不要忘记关闭记录集:MyRS.Close
。
答案 1 :(得分:0)
在进入Do While
循环之前尝试此操作: -
MyRs.MoveFirst