Concat

Posts   
 
    
Rvio33
User
Posts: 3
Joined: 08-Oct-2009
# Posted on: 10-Oct-2009 19:17:03   

Very new to LLBLGen Pro. I have read and understand your post from Posted on: 09-Aug-2008 10:58:35. My code is below. I am not understanding why or how to bind my new Resultsfield to my listbox. Can you advise what I am missing or if I did not understand your post?

*** Added info**** My db has a table that I want to pull 2 fields from: one called Capfname one called Caplname I want to concat the two fields into one fullname field and have the results show in a lisbox control. I am using C# and LLBLGen Pro

The code down below is what I though I needed to accomplish this. Although the list box dose not shows the fullname it is blank. I am guessing I have something missing that is needed in the statements so it knows to go to the list box like I used in commented lines

//lstApprover.DataTextField = EnhancedPcnCaptureMgrFieldIndex.Caplname.ToString();

I may be off and maybe this is not the best way to do get a list box with multiple fields from the DB so if that is the case you can just direct me to what I need. May even be a typdlist. As I said I am very new only 1 week into llblgen and might be on the wrong track.

Thanks in advance for your help


using (EnhancedPcnCaptureMgrCollection captmgrColl = new EnhancedPcnCaptureMgrCollection()) { //SortExpression sorterCapName = new SortExpression(); //sorterCapName.Add(EnhancedPcnCaptureMgrFields.Caplname | SortOperator.Ascending); //captmgrColl.GetMulti(null, 0, sorterCapName); lstApprover.DataSource = captmgrColl; //lstApprover.DataTextField = EnhancedPcnCaptureMgrFieldIndex.Capfname.ToString(); //lstApprover.DataTextField = EnhancedPcnCaptureMgrFieldIndex.Caplname.ToString(); //lstApprover.DataValueField = EnhancedPcnCaptureMgrFieldIndex.CaptureManagerId.ToString();

                    ResultsetFields fields = new ResultsetFields(2);
                    fields.DefineField(EnhancedPcnCaptureMgrFieldIndex.Capfname, 0, "Fname");
                    fields.DefineField(EnhancedPcnCaptureMgrFieldIndex.Caplname, 1, "Lname");
                    fields[1].ExpressionToApply = new DbFunctionCall("{0} + ' ' + {1}", new object[] { 
                    EnhancedPcnCaptureMgrFieldIndex.Capfname, EnhancedPcnCaptureMgrFieldIndex.Caplname });          
                    lstApprover.DataBind();
                }

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Oct-2009 20:59:28   

Hi there,

You are very close. Below I resume two solutions to your scenario:

DynamicList approach

// prepare field
ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(EnhancedPcnCaptureMgrFields.Caplname, 1, "FullName");
fields[0].ExpressionToApply = new DbFunctionCall("{0} + ' ' + {1}", new object[] { 
     EnhancedPcnCaptureMgrFields.Capfname, 
     EnhancedPcnCaptureMgrFields.Caplname });           

// fetch
DataTable results = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);

// bind
lstApprover.DataSouce = results;
lstApprover.DataBind();

Using this expression instead of DBFunctionCall should work as well:

new Expression(
     new Expression( EnhancedPcnCaptureMgrFields.Capfname, ExOp.Add, " "),
     ExOp.Add, 
     EnhancedPcnCaptureMgrFields.Caplnam)

Entity Collection approach

And, you also could go on the collection approach. You just need to add a custom property to your entity (in a partial class or custom code region):

public string FullName
{
     get
     {
          return this.Capfname + " " + this.Caplname;
     }
}

then, at your gui code, fetch the collection and bind it:

//fetch
EnhancedPcnCaptureMgrCollection myColl = new EnhancedPcnCaptureMgrCollection();
myColl.GetMulti(null);

//bind
lstApprover.DataSouce = myColl;
lstApprover.DataMember = "FullName";
lstApprover.DataBind();
David Elizondo | LLBLGen Support Team
Rvio33
User
Posts: 3
Joined: 08-Oct-2009
# Posted on: 12-Oct-2009 12:50:22   

I have 2 questions: I have never worked with TypedList before it is my understanding I need to create a TypedList name TypedListDAO to accomplish this code

TypedListDAO dao = new TypedListDAO();

Also

I am a little confused as to what this line of code does, is this line a representation of my fields in my DB? What are all the null for?

dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);

I am not just a copy and paste person. I like to understand what I am doing so I can apply it to future issues I come across.

Thanks in advance for your help. simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-Oct-2009 16:31:15   

The code posted above is the code to fetch a Dynamic List, which is a list of fields defined in code, with possible filters and joins.

A Typed List is a list of fields defined at Design Time, in the LLBLGen Pro Designer.

Please refer to the manual, for how to fetch a Dynamic List Generated code - Using dynamic lists, SelfServicing.

dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);

This is the line that fetches the resultSetFields (Dynamic List) I think the intellisense should help you to acknowledge what these parameters are for. in general these are for specifying filters, relations, number of rows to fetch, paging parameters...etc.