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

  • Home
  • SEARCH
  • 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 6980585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:02:38+00:00 2026-05-27T18:02:38+00:00

Even though I know that there is data for the exact SQL query I’m

  • 0

Even though I know that there is data for the exact SQL query I’m performing, for the fact that I am doing the SQL query directly on the database, I continually get an exception saying that no data exists. My code is below:

      try
        {
            dbConnection.Open();

            // Process data here.
            OdbcCommand dbCommand = dbConnection.CreateCommand();
            dbCommand.CommandText = "select forename from tblperson where personcode in (select clientcode from tblclient) and surname = '######'";
            OdbcDataReader dbReader = dbCommand.ExecuteReader();

            Console.WriteLine(dbReader.GetString(0));

            dbReader.Close();
            dbCommand.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            dbConnection.Close();
        }

Can anyone give me reasons as to why this would be happening. The query should return a single result, and I’m currently only doing this to ensure that it is working, which it doesn’t appear to be. Any help would be greatly appreciated.

  • 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-27T18:02:39+00:00Added an answer on May 27, 2026 at 6:02 pm

    After ExecuteReader is called, the reader is positioned before the first returned record. To read the first record you need to call Read()

    dbReader.Read()
    

    Or of course if there are multiple rows:

    while (dbReader.Read())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of my co-workers claims that even though the execution path is cached, there
Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
I saw that __VIEWSTATE field gets rendered even though I have set the EnableViewState=false
Even though I'm pretty sure I know why this error gets raised, I don't
So I was playing around with defining a TrieSet datatype (even though I know
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even though I've been a developer for awhile I've been lucky enough to have
Even though MDI is considered harmful , several applications (even MS Office, Adobe apps)
Even though it is possible to write generic code in C using void pointer(generic

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.