Link to home
Start Free TrialLog in
Avatar of Chris Jones
Chris JonesFlag for United States of America

asked on

Select statement skips records

i have a problem with my app when i run it i noticed that it has been skipping records can anyone help me with this
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rs As ADODB.Recordset ' recorde set for the connection 
        Dim sqlstmt As String
        Dim UIN As String
        Dim PIDM As String
        Dim fname As String
        Dim lname As String
        Dim ct As Integer = 0
        Dim temparray() As String = CType(Session.Item("course"), String())
        Call localDBConnectionOpen()
        sqlstmt = "SELECT * FROM Person"
        rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
        ' checks the users infomation to see if its correct
        While Not rs.EOF
            If CWIDT.Text = "admin" Then
                Session("CWID") = Me.CWIDT.Text.Trim
                Response.Redirect("adminlog.aspx")
            End If
            Dim itemsAreNull As Boolean = True
            If Not (temparray Is Nothing) Then
                If (temparray.Length > 0) Then
                    ' Iterate through a collection
                    For Each item As Object In temparray
                        If Not (item Is Nothing) Then
                            itemsAreNull = False
                            Exit For
                        End If
                    Next item
                End If
            End If
 
 
            If (itemsAreNull = True) Then
                Dim sorry As String = "no"
                Session("redu") = sorry
                Response.Redirect("default.aspx")
            End If
            UIN = DBGetField(rs, "UIN")
            PIDM = DBGetField(rs, "PIDM")
            If CWIDT.Text = UIN Then
 
                Session("CWID") = Me.CWIDT.Text.Trim
                fname = DBGetField(rs, "FIRSTNAME")
                lname = DBGetField(rs, "LASTNAME")
                Session("FIRSTNAME") = fname
                Session("LASTNAME") = lname
                Response.Redirect("auth.aspx")
            Else
                rs.MoveNext()
                msg.Text = "UIN is incorrect"
            End If
 
        End While
        rs = DBRecordSetDestroy(rs)
        Call localDBConnectionClose()
    End Sub

Open in new window

Avatar of prairiedog
prairiedog
Flag of United States of America image

What do you exactly mean "it has been skipping records"?
Avatar of Chris Jones

ASKER

i have over 242643 records in a table and i have a value that i am searching for and it does not find it when i use the select * statement it looks like it skipps records or something
Do you mean when you use "Select * from Person", you don't get 242643 records?
yes :)
if you are relying on this
 CWIDT.Text = UIN

for matching, please ensure you trim both the strings first before comapring.
Have you tried the query in the Query Analyzer to see how many records it returns?
What happens if you run "Select COUNT(*) As [Total] From [Person]" in the Query Analyzer?
how do i trim
ok i did the trim still did not work
i get the correct ammoun when i run Select COUNT(*) As [Total] From [Person]"
CWIDT.Text.Trim() = UIN.Trim()

if the UIN is tored as string in the db then its better to Trim, as sometime junk/null characters seep in.
ok i trimed both and still the same result
I am a little confused. You said when you run "Select * From Person" you don't get the correct total, but when you run "Select COUNT(*) As Total" you get the correct total. There must be a misunderstanding or something, because those two queries should return the same total.
If you just can't find a value from the returned data set, then the problem is in your search logic, not the "select" statement skipping records.
What about
Select * From [Person] WHERE UIN = <your value>
ok can you help me with the search logic to see if it skips the records
Can you give an example of what value you try to search for?
Also, set a break point on line 40:
If CWIDT.Text = UIN Then
What values do you have for CWID.Text and UIN?
 
i have a field in a tbale called UIN
a user puts there UIN in the textbox and i search the table field to see if it matches
if it doe snot match i move to the next record

PROBLEM
it must not search through the whole table i find some but the ones close to the bottom it does not fnd
        While Not rs.EOF
            UIN = DBGetField(rs, "UIN")
            PIDM = DBGetField(rs, "PIDM")
            If UIN.Trim() = CWIDT.Text.Trim() Then
                '  If UIN = CWIDT.Text Then
                Session("CWID") = Me.CWIDT.Text.Trim
                fname = DBGetField(rs, "FIRSTNAME")
                lname = DBGetField(rs, "LASTNAME")
                Session("FIRSTNAME") = fname
                Session("LASTNAME") = lname
                Response.Redirect("auth.aspx")
            Else
                rs.MoveNext()
                msg.Text = "UIN is incorrect"
            End If
 
        End While

Open in new window

Is UIN a string type?
yes
What happens if you change to:
If UIN.Trim().ToLower() = CWIDT.Text.Trim().ToLower() Then
 
still the same problem
Did you set the break point as I asked before? Can your report back the result?
the UIN starts off null "" and the CWIDT.text is the users unput
when i step through about 10 times i get a value in UIN that is not correct so it moves on
and goes through agian for about 10 times befor displaying a niumber
Sorry I don't quite understand your last comment, can you rephrase it?
sorry

the first time i steped into the line the UIN was "" and the users input was what he or she entered lets say "000000000" and it moved through the list but it did not find the value that the user entered
EXAMPLE

first run UIN "" CWIDT.text "000000000"
next run  UIN "123456789" CWIDT.Text"000000000"
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>>it moved through the list but it did not find the value that the user entered
Do you get any error message?
ok it runs a lot faster but i still get the same error
>>>ok it runs a lot faster but i still get the same error
So, what error? That's what I asked in my last post.
ok  i think that fixed the problem

you are awesome i need to write better code i think
Great expert worked with me and di dnot give up
>ok it runs a lot faster

for sure :)

>i need to write better code i think
just "more organized", "more optimized".

:)