Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hy
 
I have a combobox in my program.
 
In my database client with the same name. The dysplay member of my combo box is FirstName + LastName + MiddleName.
 
The combobox is set to:
 
AutoCompletMode to: Suggest
AutoCompletSource to : ListItems.
 
When i search a client name (2 record of the name client in the database), in my combo box appear only the second client name insertad in database.
 
How to show all name of my clients?
 
This is my code for pupulating tha combobox:
 
Program.Connection.CommandText = "SELECT LastName + ', ' + FirstName + ' ' + IIF(MiddleName, MiddleName,'') AS NumeComplet, ClientId FROM Clients GROUP BY ClientId, LastName, FirstName, MiddleName ORDER BY ClientId";
            DataTable Table = new DataTable();
 
            Program.Connection.FillDataTable(Table, true);
            cboNumeClient.DataSource = Table;
            cboNumeClient.DisplayMember = "NumeComplet";
            cboNumeClient.ValueMember = "ClientId";
            cboNumeClient.Focus();
 
Is not a solution to remove the duplicate names from database.
 
If i use the "Suggest" mode for search a client name, in the list are show the last record added for the same client name.
 
If i use the arrow to select a client name, in the the list of the combo box are show all my clients, ad when i select one and click outside on a another control, the combo box autoselect the first client with the same name.
Posted 1-Feb-13 1:18am
Edited 1-Feb-13 8:31am
v2
Comments
CHill60 at 1-Feb-13 6:23am
   
Post the code you're using to populate the combobox
aciobanita constantin at 4-Feb-13 8:40am
   
This is the code to populate my combobox:
 
Program.Connection.CommandText = "SELECT LastName + ', ' + FirstName + ' ' + IIF(MiddleName, MiddleName,'') AS NumeComplet, ClientId FROM Clients GROUP BY ClientId, LastName, FirstName, MiddleName ORDER BY ClientId";
DataTable Table = new DataTable();

Program.Connection.FillDataTable(Table, true);
cboNumeClient.DataSource = Table;
cboNumeClient.DisplayMember = "NumeComplet";
cboNumeClient.ValueMember = "ClientId";
cboNumeClient.Focus();
 
the conection stings are in a separate class.
Kishor Deshpande at 1-Feb-13 6:25am
   
In your stored procedure, are you using distinct clause?
Can you show me some code of fetching values from DB?
ryanb31 at 1-Feb-13 8:03am
   
It's possible you are removing the duplicates in SQL. You'll have to post your SQL and your C# for us to help.
Muthuraja Irullandi at 1-Feb-13 10:45am
   
Are you using Distinct keyword in your query?
CHill60 at 1-Feb-13 14:27pm
   
Are the ClientId values definitely different for the records where the client has the same name?
aciobanita constantin at 1-Feb-13 15:03pm
   
Yes, the ClientID is different, is the primarykey in my database.
Member 2053006 at 8-Feb-13 11:20am
   
Have you tried removing the GROUP BY section? My SQL is a bit rusty I am afraid, but it looks like that section is not needed and could cause problems.
 
Do NumeComplet and ClientId looking correct if you try enumerating the DataTable?
aciobanita constantin at 11-Feb-13 4:18am
   
I can't remove GROUP BY, my query will not work whiteout GROUP BY.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

"Is not a solution to remove the duplicate names from database"
 
Then why are you doing just that?
If you have two rows that have identical names and you use GROUP BY on that name, you will only get one row returned...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 BillWoodruff 108
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100