Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I want show a full name of a client in a combobox (C#).

But, the full name have three rows fullname, middlename, lastname., middlename can't be empty.

C#
Program.Connection.CommandText = "select LastName + ', ' + FirstName AS NumeComplet, ClientId from Clients ORDER BY LastName";
            DataTable Table = new DataTable();
            Program.Connection.FillDataTable(Table, true);
            cboNumeClient.DataSource = Table;
            cboNumeClient.DisplayMember = "NumeComplet";
            cboNumeClient.ValueMember = "ClientId";
            cboNumeClient.Focus();


This is the code to show the fullname (firstname + lastname).

How to show (firstname + lastname + middlename)?


I try to use...
C#
Program.Connection.CommandText = "select LastName + ', ' + FirstName + MiddleName AS NumeComplet, ClientId from Clients ORDER BY LastName";


but, when middlename is empty, my DisplayMember of the combobox is empty.
Posted

Try:
SQL
SELECT LastName + ', ' + FirstName + ' ' + ISNULL(MiddleName, '') AS NumeComplet, ClientId FROM Clients ORDER BY LastName
 
Share this answer
 
Comments
ridoy 13-Oct-12 10:05am    
+5
C#
SELECT LastName + ', ' + FirstName + ' ' + IIF(MiddleName, MiddleName,'') AS NumeComplet, ClientId FROM Clients GROUP BY ClientId, LastName, FirstName, MiddleName
 
Share this answer
 
SELECT FName+' '+MName+' '+LName AS EmployeeName, EmployeeCode FROM EmployeePIMSInfo
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900