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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:58:18+00:00 2026-05-17T00:58:18+00:00

I have a problem while checking a hashtable value. In the code below I

  • 0

I have a problem while checking a hashtable value. In the code below I am storing 60 values in the hashtable “hash”. One of the values is (or can be) Null. I am checking each entry against its corresponding entry in hashtable “hash1”, to see if they match each other. If they don’t match I want to check if the value in “hash” is Null, but I can’t catch it – it’s falling through the ‘else’ part). How can I overcome this problem?

if (hash[j].ToString() == "")
{
    NotAnswerQuestionCount++;
}

My Code:

int ctAnsCount=0, flAnsCount=0,NotAnswerQuestionCount=0;
SqlDataAdapter sda = 
    new SqlDataAdapter("select quesno,[Key] from Answerkey" ,con);
DataSet ds = new DataSet();
sda.Fill(ds);

Hashtable hash = new Hashtable();

for (int i = 0; i < 60; i++)
{
    hash[i+1] = ResultsListBox.Items[i].ToString();
}

Hashtable hash1 = new Hashtable();

for (int i = 0; i < 60; i++)
{
    hash1[i+1] = ds.Tables[0].Rows[i][1].ToString();
}

for (int j = 1; j <=60; j++)
{
    if (hash[j].ToString() != hash1[j].ToString())
    {
        if (hash[j].ToString() == "")
        {
            NotAnswerQuestionCount++;
        }
        //else


        flAnsCount++;
    }
    else
    {           
        ctAnsCount++;    
    }
}
  • 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-17T00:58:19+00:00Added an answer on May 17, 2026 at 12:58 am

    I don’t think you mean null, I think you mean empty. You’re checking the contents of ‘hash’, which looks like it is filled from a ListBox, but AFAIK a ListBox item can’t be null. Also, you’re checking to see if it matches the empty string ("").

    How do you know that you have an empty string in the ListBox? Try Trim-ing the value before you check it (i.e. if (hash[j].ToString().Trim() == "") to catch empty strings as well as strings that only contain whitespace. Alternatively output the contents of each ListBox item to debug, bracketed by a delimiter, to check that you’ve actually got, like so:

    foreach (Object o in ResultsListBox.Items) {
      Debug.WriteLine("'" + o.ToString() + "'");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I'm providing a backlink selling service, but I have problem while checking the sold
I have problem while loading data into html select when users press or click
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
i have a problem while loading a UITableView on UITabBarController, i got this error
I have a problem while publishing on the Market. My application does not use
I have very strange problem while I am submitting a practice problem on codechef.

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.