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 6704183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:15:33+00:00 2026-05-26T07:15:33+00:00

I think nothing’s wrong with the connection because when I open it, it does

  • 0

I think nothing’s wrong with the connection because when I open it, it does not throw any error. So I guess the error is when I’m executing a command. This is my code:

OleDbCommand cmd = new OleDbCommand("SELECT * FROM cars", conn);
cmd.CommandType = CommandType.Text;
int numbers = cmd.ExecuteNonQuery();

I tried using a message box to display the value of numbers but the result is always 0. The table cars contains 5 records. So why am I not getting the correct 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-26T07:15:34+00:00Added an answer on May 26, 2026 at 7:15 am

    To the anonymous downvoter, the key part of the OP:

    I tried using a message box to display the value of numbers but the
    result is always 0. The table cars contains 5 records. So why am I not
    getting the correct results?..

    The OP is obviously trying to get a count of records in the table (a scalar aggregate) and not all of the table data.

    My answer:

    That’s because your query is returning a table and not a scalar value and you’re calling the incorrect function. Your query should be should be:

    "SELECT COUNT(*) FROM cars"
    

    And ExecuteNonQuery doesn’t actually expect any results to be returned. (You usually run insert, update and delete operations with ExecuteNonQuery.) You should be using ExecuteScalar which expects a single-valued result such as count(*).

    All together now:

    OleDbCommand cmd = new OleDbCommand("SELECT count(*) FROM cars", conn);
    cmd.CommandType = CommandType.Text;
    int numbers = cmd.ExecuteScalar();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think the file that is produced is an .asm file, any idea how
I think the error has to be in a incompatibility with IE8 and the
I am starting to think something on my eclipse has gone completely wrong. I've
I think it is by design and there is nothing can be done about
Im trying to think how to do this with html elements. There is nothing
I can't think of a good title, but my question is not as naive
I don't think simplest is subjective. Looking for a hostable photo gallery that does
I think there is something wrong with my selectors that make my jquery popup
I think I searched for an answer about my problem but I did not
I think I've successfully installed the FirePHP module in Kohana 3.1 but I'm not

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.