OleDbException(0x80004005):未指定错误?

时间:2010-06-25 01:20:01

标签: c# asp.net vb.net oledb datareader

我创建了一个按钮(Next)以在名为CHAPTERS的表格中导航;

我的问题是按钮工作两次,有时三次。之后我得到[未指定错误]。

这是我的代码:

Dim S As Integer = Integer.Parse(Request.QueryString("id"))
Dim RQ As String
Dim DR As OleDbDataReader
RQ = "SELECT ID_C FROM CHAPTRES"
DR = Connexion.lecture(RQ)
While DR.Read
    If DR.GetInt32(0) = S Then
            Exit While
        End If
    End While

    If DR.Read = True Then
        S = DR.GetInt32(0)
        Response.Redirect("Chapitre.aspx?id=" & S)
    Else   
        // End of records (stop reading)
    End If

感谢。

UPDATES :

我的connecter文件中的lectureConnexion.vb函数:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Public Class Connexion

Public Shared Function conecter() As OleDbConnection
    Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & System.AppDomain.CurrentDomain.BaseDirectory & "/Learning.mdb")
    MyConnexion.Open()
    Return MyConnexion
End Function

Public Shared Function lecture(ByVal requete As String) As OleDbDataReader
    Dim Mycommand As OleDbCommand = conecter().CreateCommand()
    Mycommand.CommandText = requete
    Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
    Return myReader

End Function

1 个答案:

答案 0 :(得分:1)

您的问题可能是您没有关闭/处置OleDbDataReader。 Response.Redirect调用会将您带到另一个页面而不关闭打开的数据阅读器。

尝试将最后一段代码修改为:

If DR.Read = True Then 
    S = DR.GetInt32(0) 
    DR.Close()
    DR.Dispose()
    Response.Redirect("Chapitre.aspx?id=" & S) 
Else    
    // End of records (stop reading) 
End If 

更新:如果您提供了更多信息,显然会有所帮助,例如,此示例中的代码行可能会抛出异常。

相关问题