Combining FirstName + LastName fields in Combobox

Posts   
 
    
mayvelous avatar
mayvelous
User
Posts: 5
Joined: 06-Feb-2007
# Posted on: 20-Jun-2007 06:46:03   

Hello,

I like to combine 2 fields, "FirstName" + "LastName" as "FullName" to display in combobox with the fieldID as the valuemember. At the moment, I'm returning DataTable with list of fields.

public DataTable SelectAllStaff()
{
            ResultsetFields fields = new ResultsetFields(2);
            fields[0] = StaffFields.StaffId;

            // Want to combine like the following:
            // fields[1] = StaffFields.FirstName + " " + StaffFields.LastName;

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                DataTable tbl = new DataTable();
                adapter.FetchTypedList(fields, tbl, null);
                return tbl;
            }
 }

And I'm getting error on this line: fields[1] = StaffFields.FirstName + " " + StaffFields.LastName;

Cannot implicitly convert type 'SD.LLBLGen.Pro.ORMSupportClasses.Expression' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2'. An explicit conversion exists (are you missing a cast?)

Is there a way to dynamically combine two fields instead of writing storeproc for that and call it using RetrivalProcedure calls? Or any other ways to solve this please?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Jun-2007 09:00:44   

Using an expression, something like the following should work:

            ResultsetFields fields = new ResultsetFields(2);
            fields.DefineField(StaffFields.StaffId, 0);
            fields.DefineField(StaffFields.StaffFirstName, 1, "FullName");

            Expression someExp = new Expression(" ", ExOp.Add, StaffFields.StaffLastName);
            Expression fullExp = new Expression(StaffFields.StaffFirstName, ExOp.Add, someExp);
            fields[1].ExpressionToApply = fullExp;