我创建了一个按钮 ( 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
andlecture
函数: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