[英]OleDbException (0x80004005): Not specified error?
我創建了一個按鈕( 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 :
這在我的Connexion.vb
文件中具有connecter
和lecture
功能:
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
您的問題可能是您沒有關閉/處置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
更新:如果您提供了更多信息,例如在此示例中確切的代碼行引發異常,那顯然會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.