Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 975161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:32:30+00:00 2026-05-16T03:32:30+00:00

This is incredibly urgent, I need to present this application in 3 and a

  • 0

This is incredibly urgent, I need to present this application in 3 and a half hours.

My application checks against a data source to see if a value exists in the database and changes values depending on whether or not the value in question was found.
The problem is that I’ve run the sql query with the value in question in SSMS and no rows were returned, and yet, my DataReader says it has rows.

This means that my application is reporting inaccurately.
Here’s my code:

Using conn As New SqlConnection("Data Source=.\SQLEXPRESS; Initial Catalog=Testing;       Integrated Security=True;")
    Dim cmd As New SqlCommand(sql, conn)

    conn.Open()
    Dim reader As SqlDataReader = cmd.ExecuteReader

    If reader.HasRows Then
       Value = True
       AcctNumber = reader(1)
    End If

    reader.Close()
End Using

I’ve removed code that’s not relevant to this post, but what you may want to know is:

Value is Boolean
AcctNumber is a String

As this is an application for work, I’d rather not include the SQL Query. The problem is the reader. If I comment out Value = True, I get the right info, but leaving that out will mean that in a case where Value should be True, it’ll report inaccurately as well.

Thanks in advance!

EDIT: Full Source Code:

Case "Business"
    ' Change the number format to local because that's what it is in the db
    If Microsoft.VisualBasic.Left(NumberToCheck, 2) = "27" Then
        NumberToCheck = NumberToCheck.Replace(Microsoft.VisualBasic.Left(NumberToCheck, 2), "0")
    End If

    Dim sql As String = "SELECT a.TelNumber, c.AccountNumber " & _
            "FROM TelInfo a " & _
            "INNER JOIN Customers b ON a.CustID = b.pkguidId " & _
            "INNER JOIN Accounts c ON b.pkguidId = c.CustID " & _
            "WHERE a.TelNumber = '" & NumberToCheck & "'"
    Using conn As New SqlConnection("Data Source=.\SQLEXPRESS; Initial Catalog=Testing; Persist Security Info=True; " & _
        "User Id=JoeSoap; Password=paoseoj;")
        Dim cmd As New SqlCommand(sql, conn)

        conn.Open()
        Dim reader As SqlDataReader = cmd.ExecuteReader

        If reader.Read Then
            Value = True
            AcctNumber = reader(1)
         End If

        reader.Close()
    End Using

On the comments below made before 08/02/10 (mm/dd/yy):

Value is just a boolean that gets returned by the function to indicate that the searched telephone number (NumberToCheck) exists in the database.

So…

Private AcctNumber As String

Dim val As Boolean = False
val = CheckNumber("3235553469")
If val Then
    ' AcctNumber will have been set by CheckNumber
    Label1.Text = AcctNumber
End If

val will only be returned True if the NumberToCheck (in this example 3235553469) exists in the database.

Having copied the value of NumberToCheck into SSMS and testing the query there, I can verify that the query does work as expected.

No, I can’t populate a DataSet because of the volume of information in the table (+/- 9.5m rows). Even with the ‘WHERE’ filter, the query is too heavy on resources and eventually ends in an OutOfMemory Exception which is why I went with a DataReader.

I’m going to try the ExecuteScalar option as suggested as an answer by Darryl now, will update with the results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:32:31+00:00Added an answer on May 16, 2026 at 3:32 am

    In the immortal words of Homer Simpson… “DOH!!”

    I just had a look on the database that my application searches for the telephone numbers and, I don’t know how I could have missed it, but the value I’m searching for is actually there.

    The problem is, therefore, not likely anything to do with my code, but rather the data…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well this is incredibly frustrating. After being nagged by Rails that I need to
I need to redirect /search?keywords=somesearchterm to /search/somesearchterm This seems incredibly basic but I've been
MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily
We're using Stored Procedures for every query to the DB. This seems incredibly un-
This is an incredibly simple question (I'm new to Python). I basically want a
I'm really stumped on this incredibly simple mapping. It looks just like one of
This seems incredibly similar to a question I had answered just a few days
I'm sure this is incredibly common with as OOP centered as Java is. In
I need to develop a file indexing application in python and wanted to know
I'm sure this is incredibly simple for somebody, but I am failing to grasp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.