pouvez-vous s'il vous plaît m'aider à trouver la raison du mystère que j'ai trouvé? Dans le code ci-dessous, je crée un DataTable et le filtre. Quand j'utilise filter1, tout fonctionne comme prévu. Lorsque j'utilise filter2, tout fonctionne comme prévu uniquement si la variable SubsectionAmount est inférieure à 10. Dès que j'ai défini SubsectionAmount = 10, le tableau dr2 renvoie Nothing. Je ne peux pas trouver ce qui ne va pas. Voici le code:DataTable Filter mystère
Imports System.Data
classe partielle FilterTest Hérite System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call FilterTable()
End Sub
Sub FilterTable()
Dim dtSubsections As New DataTable
Dim SectionID As Integer, SubsectionID As Integer
Dim SubsectionAmount As Integer
Dim filter1 As String, filter2 As String
Dim rowID As Integer
Dim dr1() As DataRow, dr2() As DataRow
With dtSubsections
.Columns.Add("Section")
.Columns.Add("Subsection")
.Columns.Add("FieldString")
SectionID = 1
SubsectionAmount = 10 '9
For SubsectionID = 1 To SubsectionAmount
.Rows.Add(SectionID, SubsectionID, "abcd" & CStr(SubsectionID))
Next SubsectionID
For rowID = 0 To .Rows.Count - 1
Response.Write(.Rows(rowID).Item(0).ToString & " " _
& .Rows(rowID).Item(1).ToString & " " _
& .Rows(rowID).Item(2).ToString & "<BR>")
Next
SubsectionID = 1
filter1 = "Section=" & SectionID & " AND " & "Subsection=" & SubsectionID
filter2 = "Section=" & SectionID & " AND " & "Subsection=" & SubsectionID + 1
dr1 = .Select(filter1)
dr2 = .Select(filter2)
Response.Write(dr1.Length & "<BR>")
Response.Write(dr2.Length & "<BR>")
If dr1.Length > 0 Then
Response.Write(dr1(0).Item("FieldString").ToString & "<BR>")
End If
If dr2.Length > 0 Then
Response.Write(dr2(0).Item("FieldString").ToString & "<BR>")
End If
End With
End Sub
End Class
Je pensais que cela aussi, mais juste testé, et ce code fonctionne comme prévu: Dim As String = de "Bibble" & x + 1 produit bibble4 lorsque x = 3 – NibblyPig
Je l'ai utilisé à la fois "section =" & SectionID & "AND" & "Subsection =" & (SubsectionID + 1) et même "Section =" & SectionID & "AND" & "Subsection = 2". Il a produit le même mystère: ne peut pas filtrer le datatable. Plus de pensées s'il vous plaît? – user283897