2

Nextというテーブル内を移動するためのボタン ( ) を作成しましたCHAPTERS

私の問題は、ボタンが 2 回、場合によっては 3 回機能することです。すると【指定外エラー】が出ます。

これは私のコードです:

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 :

これはconnecterlecture私のConnexion.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
4

1 に答える 1

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 

更新: この例のコードのどの行が例外をスローしているかなど、より多くの情報を提供すると明らかに役立ちます。

于 2010-06-25T01:50:50.697 に答える