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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:40:19+00:00 2026-06-07T16:40:19+00:00

I had created this method to check number of this record in the table

  • 0

I had created this method to check number of this record in the table
but it gives me this error message when the value of count(*) is 0
i use this library to connect oracle db

using Oracle.DataAccess.Client;

 private int checkPort(int portID)
        {
            int intCount = 0;
            try
            {
                OracleCommand oraCommand = new OracleCommand();
                oraCommand.Connection = new DBManager().getConnection();
                oraCommand.CommandText = "select count(*) as num from wireless_port_oid where port_id=:port_id";
                oraCommand.Parameters.Add(":port_id", portID);

                OracleDataReader Reader= oraCommand.ExecuteReader();


                return intCount;
                while (**Reader.Read()**)//it gives exception here
//The err Operation is not valid due to the current state of the object.
                {  
                    intCount =Convert.ToInt32(Reader[0]);
                    Reader.Close();
                    oraCommand.Connection.Close();
                    oraCommand = null;
                    if (intCount > 0)
                    {
                        return 1;
                    }
                }
                Reader.Close();
                Reader.Dispose();
                oraCommand.Connection.Close();
                oraCommand.Connection.Dispose();
                oraCommand.Dispose();
                return 0;

            }
            catch (OracleException exception)
            {
                Console.WriteLine(exception.Message);
                return 0;
            }
        }
  • 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-06-07T16:40:21+00:00Added an answer on June 7, 2026 at 4:40 pm

    You’re closing the reader on Count = 0 and then trying to read it again in the while loop.

    while (Reader.Read())//it gives exception here
    //The err Operation is not valid due to the current state of the object.
                    {  
                        intCount =Convert.ToInt32(Reader[0]);
                        Reader.Close();
                        oraCommand.Connection.Close();
                        oraCommand = null;
                        if (intCount > 0)
                        {
                            return 1;
                        } 
                        // if intCOunt == 0 then what? loop again
                    }
    

    But your code is not valid – I just noticed that you have a return intCount; just before the line you says has an error. I assume that that’s just example typo.

    I would refactor your code to take adavantage of C#’s using statement:

    private int checkPort(int portID) {
        string sql = "select count(*) as num from wireless_port_oid where port_id=:port_id";
        int intCount = 0;
        try {
            using(OracleCommand oraCommand = new OracleCommand()) {
                using(oraCommand.Connection = new DBManager().getConnection()) {
                    oraCommand.CommandText = sql;
                    oraCommand.Parameters.Add(":port_id", portID);
                    intCount = oraCommand.ExecuteScalar();
                }
            }
        }
        catch (OracleException exception) {
            Console.WriteLine(exception.Message);
                // may be you shouldn't return 0 here possibly throw;
        }
    
        return intCount;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had created one HTML page for my experiance. In this i had use
This is what I want: I had created the top red layout by this
I had created a Lib Project with a class inherits ServiceBase but when I
Probably this is just the way Rails works, but I want to double-check because
I had no idea of how to call out the method to check if
[I had this sketched out as a comment elsewhere but decided to create a
So I had to create this splash page in a very short amount of
For this assignment I had to create my own string class. I initially wrote
I had created one div window which is draggable,and created one child div (with
I had created the following view, SELECT currency_cd, SUM(comprate) AS salary, employee_code, (SELECT SUM(c.comprate)

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.