Chris Jones
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
What do you exactly mean "it has been skipping records"?
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?
ASKER
yes :)
if you are relying on this
CWIDT.Text = UIN
for matching, please ensure you trim both the strings first before comapring.
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?
What happens if you run "Select COUNT(*) As [Total] From [Person]" in the Query Analyzer?
ASKER
how do i trim
ASKER
ok i did the trim still did not work
ASKER
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.
if the UIN is tored as string in the db then its better to Trim, as sometime junk/null characters seep in.
ASKER
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.
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>
Select * From [Person] WHERE UIN = <your value>
ASKER
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?
If CWIDT.Text = UIN Then
What values do you have for CWID.Text and UIN?
ASKER
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
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
Is UIN a string type?
ASKER
yes
What happens if you change to:
If UIN.Trim().ToLower() = CWIDT.Text.Trim().ToLower( ) Then
If UIN.Trim().ToLower() = CWIDT.Text.Trim().ToLower(
ASKER
still the same problem
Did you set the break point as I asked before? Can your report back the result?
ASKER
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
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?
ASKER
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
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
ASKER
EXAMPLE
first run UIN "" CWIDT.text "000000000"
next run UIN "123456789" CWIDT.Text"000000000"
first run UIN "" CWIDT.text "000000000"
next run UIN "123456789" CWIDT.Text"000000000"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>>it moved through the list but it did not find the value that the user entered
Do you get any error message?
Do you get any error message?
ASKER
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.
So, what error? That's what I asked in my last post.
ASKER
ok i think that fixed the problem
you are awesome i need to write better code i think
you are awesome i need to write better code i think
ASKER
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".
:)
for sure :)
>i need to write better code i think
just "more organized", "more optimized".
:)