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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:34:01+00:00 2026-05-29T18:34:01+00:00

The data reader named eventreader can be empty and i’m trying to work out

  • 0

The data reader named eventreader can be empty and i’m trying to work out an appropriate statement to detect if the datareader contains rows and if the require record exists.

oledbexecute("SELECT [Unit No] FROM UnitOpenAtEvent WHERE [Event ID]='" + strDate + "'");
            eventReader = dbcommand.ExecuteReader();
            for (int i = 0; i < checkboxEvent.Items.Count; i++)
            {
                if (checkboxEvent.GetItemCheckState(i) == CheckState.Checked)
                {
                    if (eventReader["Unit No"] != DBNull.Value)
                    {
                        while (eventReader.Read())
                        {
                            if (eventReader["Unit No"].ToString() == checkboxEvent.Items[i].ToString())
                            {
                                oledbexecute("INSERT INTO UnitOpenAtEvent ([Event ID],[Unit No]) VALUES ('" + strDate + checkboxEvent.Items[i].ToString() + "'");
                                intReader = dbcommand.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {
                        oledbexecute("INSERT INTO UnitOpenAtEvent ([Event ID],[Unit No]) VALUES ('" + strDate + checkboxEvent.Items[i].ToString() + "'");
                        intReader = dbcommand.ExecuteNonQuery();
                    }
                }
                else if (checkboxEvent.GetItemCheckState(i) == CheckState.Unchecked)
                {

                   // this is effectively a copy of above
                 }
            }
  • 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-29T18:34:03+00:00Added an answer on May 29, 2026 at 6:34 pm

    You can check if the DataReader has any rows using e.g.

    if (eventReader.HasRows)
    

    Update:
    Following from comment below re: IDataReader…

    You could do something like this (shortened to include the most relevant bits for conciseness)

    eventReader = dbcommand.ExecuteReader();
    bool hasRow = eventReader.Read();
    if (hasRow)
    {
        for (int i = 0; i < checkboxEvent.Items.Count; i++)
        {
            ...
                ...
                while (hasRow)
                {
                    // Code in here to deal with each row
                    hasRow = eventReader.Read();
                }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want in the case of an empty data reader to output the field
I want to create a similar behavior to the data reader class but for
When working with namespaces such as System.Data.Odbc or System.Data.OracleClient the various data reader methods
I use a stream reader to import some data and at the moment I
What is the best way to take a data file that contains a header
I'm getting an exception from SQL Data Reader (MS SQL as datastore) and I'd
Please help, how do I really use data reader in vb.net. I'm using odbc
I'm using a third party library which returns a data reader. I would like
I got the error message There is an open data reader associated with this
I'm using C# and .NET 3.5, trying to import some data from old dbf

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.