本文介绍了三行合一(别名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想在组合框(C#)中显示客户端的全名.

但是,全名有三行全名,中间名,姓氏.中间名不能为空.

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.

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...

Program.Connection.CommandText = "select LastName + ', ' + FirstName + MiddleName AS NumeComplet, ClientId from Clients ORDER BY LastName";



但是,当Middlename为空时,组合框的DisplayMember为空.



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

推荐答案

SELECT LastName + ', ' + FirstName + ' ' + ISNULL(MiddleName, '') AS NumeComplet, ClientId FROM Clients ORDER BY LastName


SELECT LastName + ', ' + FirstName + ' ' + IIF(MiddleName, MiddleName,'') AS NumeComplet, ClientId FROM Clients GROUP BY ClientId, LastName, FirstName, MiddleName



这篇关于三行合一(别名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 20:05