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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:13+00:00 2026-05-27T11:32:13+00:00

Ok, My counting does work somewhat, meaning that it display correct number when data

  • 0

Ok, My counting does work somewhat, meaning that it display correct number when data is added and deleted.

The problem is that if I add only 1 entry, I am displayed that I have 1 entry, but if I delete the only entry there is, my counter is still showing 1. Why not 0?

This is how I do it (the fields where I am updating my panel titles are on the bottom):

    public void DisplayFileContent(string filePath)
    {
        lvPC.Items.Clear();
        lvWeb.Items.Clear();
        lvSerialCode.Items.Clear();

        string hashShortPass = hash.ShortHash(storedAuth.Password);
        // Counting all entries.
        int countEntries = 0;

        int countPC = 0;
        int countWeb = 0;
        int countSerial = 0;

        string connectionString =
            @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};
              Persist Security Info=False; Jet OLEDB:Database Password={1};";

        // Encrypting/Decrypting  data.
        Security security = new Security();

        using (OleDbConnection connection = new OleDbConnection())
        {
            connection.ConnectionString = string.Format(connectionString, filePath, hashShortPass);

            using (OleDbCommand command = new OleDbCommand
                ("Select * FROM PersonalData", connection))
            {
                try
                {
                    // Open database connection.
                    connection.Open();

                    using (OleDbDataReader read = command.ExecuteReader())
                    {
                        // Checking if there is any data in the file.
                        if (read.HasRows)
                        {
                            // Reading information from the file.
                            while (read.Read())
                            {
                                // Count all entries read from the reader.
                                countEntries++;

                                if (security.DecryptAES(read.GetString(1), 
                                    storedAuth.Password, storedAuth.UserName) 
                                        == "PC Password")
                                {
                                    // Count PC passwords.
                                    countPC++;
                                    PC.Tag = read.GetInt32(0);
                                    lvPC.Items.Add(PC);
                                }
                                else if (security.DecryptAES(read.GetString(1), 
                                    storedAuth.Password, storedAuth.UserName) 
                                        == "Web Site Password")
                                {
                                    countWeb++;
                                    Web.Tag = read.GetInt32(0);
                                    lvWeb.Items.Add(Web);
                                }
                                else if (security.DecryptAES(read.GetString(1), 
                                    storedAuth.Password, storedAuth.UserName) 
                                        == "Serial Code")
                                {
                                    countSerial++;
                                    Serial.Tag = read.GetInt32(0);
                                }

                                tabPage1.Text = "PC Passwords ( " + countPC + " )";
                                tabPage2.Text = "Web Site Passwords ( " + countWeb + " )";
                                tabPage3.Text = "Serial Codes ( " + countSerial + " )";
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
        }
    }
  • 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-27T11:32:14+00:00Added an answer on May 27, 2026 at 11:32 am

    The problem is that if you delete an entry, the code that updates the labels is not getting executed.

    You need to move the following block:

    tabPage1.Text = "PC Passwords ( " + countPC + " )";
    tabPage2.Text = "Web Site Passwords ( " + countWeb + " )";
    tabPage3.Text = "Serial Codes ( " + countSerial + " )";
    

    after the } associated with this statement:

    if (read.HasRows)
    

    Also, since the HasRows is not needed, you can rewrite it something like:

    using (OleDbDataReader read = command.ExecuteReader())
    {
        // Reading information from the file.
        while (read.Read())
        {
            // Count all entries read from the reader.
            countEntries++;
    
            if (security.DecryptAES(read.GetString(1), 
                storedAuth.Password, storedAuth.UserName) 
                    == "PC Password")
            {
                // Count PC passwords.
                countPC++;
                PC.Tag = read.GetInt32(0);
                lvPC.Items.Add(PC);
            }
            else if (security.DecryptAES(read.GetString(1), 
                storedAuth.Password, storedAuth.UserName) 
                    == "Web Site Password")
            {
                countWeb++;
                Web.Tag = read.GetInt32(0);
                lvWeb.Items.Add(Web);
            }
            else if (security.DecryptAES(read.GetString(1), 
                storedAuth.Password, storedAuth.UserName) 
                    == "Serial Code")
            {
                countSerial++;
                Serial.Tag = read.GetInt32(0);
            }
        }
    }
    
    tabPage1.Text = "PC Passwords ( " + countPC + " )";
    tabPage2.Text = "Web Site Passwords ( " + countWeb + " )";
    tabPage3.Text = "Serial Codes ( " + countSerial + " )";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to get arround the annoying problem that when counting how
Does anyone know how to or have some code on counting the number of
I've a simple flash application that does counting on button click. I load it
Possible Duplicate: How does the new automatic reference counting mechanism work? Can someone explain
Joel mentioned counting the number of set bits in a byte as a programming
I believe (from some research reading) that counting down in for-loops is actually more
So on Project Euler the Problem 4 states the following: A palindromic number reads
Does anyone know any system wich work like facebook request, message, notification bubble system?
I've been asked (as part of homework) to design a Java program that does
In a lay-man terminology how does the garbage collection mechanism work? How an object

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.