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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:51:27+00:00 2026-05-20T02:51:27+00:00

In my winforms app, I have a list view control that is populated with

  • 0

In my winforms app, I have a list view control that is populated with new order information.

I am using DISTINCT(something) to get only 1 of each thing in the database table, and I am also doing a check in C# so that if it is already in the listview control, then not to add it.

But it juust keeps adding junk from the table that is already in the listview control, and it is also NOT obeying the DISTINCT command!

Here is my code, any help at all is really appreciated, thanks:

// Check for new orders.
            MySql.Data.MySqlClient.MySqlConnection msc = new MySql.Data.MySqlClient.MySqlConnection(cs);
            try
            {



                this.Cursor = Cursors.WaitCursor;

                msc.Open();

                // Check for orders now.
                string st = "SELECT DISTINCT(sessionid), firstname, lastname, email, streetaddress, suburb, postcode, state, phone, company FROM mysql_9269_dbase.order";
                MySql.Data.MySqlClient.MySqlCommand cd = new MySql.Data.MySqlClient.MySqlCommand(st, msc);
                MySql.Data.MySqlClient.MySqlDataReader msdr = cd.ExecuteReader();

                while (msdr.Read())
                {
                    if (thelist.Items.Count == 0 || !thelist.Items[0].Text.Contains(msdr[0].ToString()))
                    {
                        ListViewItem LItem = new ListViewItem(msdr[0].ToString());
                        ListViewItem.ListViewSubItemCollection SubItems = new ListViewItem.ListViewSubItemCollection(LItem);

                        SubItems.Add(msdr[1].ToString());
                        SubItems.Add(msdr[2].ToString());
                        SubItems.Add(msdr[3].ToString());
                        SubItems.Add(msdr[4].ToString() + " " + msdr[5].ToString() + " " + msdr[6].ToString() + " " + msdr[7]);
                        SubItems.Add(msdr[8].ToString());
                        SubItems.Add(msdr[9].ToString());

                        thelist.Items.Add(LItem);

                        thelist.Update();
                    }

                }


            }
            catch (Exception en)
            {
                MessageBox.Show(en.Message, "Uh, oohhhhhh!");
            }
            msc.Close();

            this.Cursor = Cursors.Arrow;
  • 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-20T02:51:28+00:00Added an answer on May 20, 2026 at 2:51 am

    Not sure about the database stuff, but it seems you are only checking if the FIRST element in your listbox is the same as the one you are about to add:

     if (thelist.Items.Count == 0 || !thelist.Items[0].Text.Contains(msdr[0].ToString()))
    

    you need to loop through the entire list. Something like this perhaps (not tested)?

     var found = false;
     foreach (var item in thelist.Items)
     {
       if (item.Text.Contains(msdr[0].ToString())
       {
         found = true;
         break;
       }
     }
     if (thelist.Items.Count == 0 || !found)
     {
       ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small winforms app that creates a new event log source. I
I'm working on a WinForms app and I have a user control in it.
So we have a winforms app that in the task manager should anywhere from
We have a WinForms app that runs fine on x86, but has many third-party
I have a small WinForms app that utilizes a BackgroundWorker object to perform a
I have a Winforms App in C# with a ListView control. This ListView shows
I have a Winforms app that allows the user to drag and drop some
i have a c# winform app that contains a listview control. i would like
I have a WinForms app built using Visual Studio 2005, including the crystal reports
Winforms .net 3.5 app. In my app I have a generic class that looks

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.