Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

(Please Select), ... Adams, Jon ... Baker Sue ... how remove comma after (Please Select) in LINQ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ronald S. Cook - 02 Mar 2008 12:04 GMT
The below code works, but returns a list like:

(Please Select),
Adams, Jon
Baker, Sue
Davis, Don

... i.e. there's a comma appended to (Please Select) that I'd really like to
get rid of.

Here's the code:

***************************************************
'1) Build database query.
Dim _Query As IEnumerable(Of Employee) = _
From e In dc.Employees _
Where e.Lookup.LookupCode <> "INA" _
Order By e.EmployeeLastName, _
e.EmployeeFirstName

'2) Execute query and store results in list.
Dim _List As IList(Of Employee) = _Query.ToList()

'3) Insert extra entry in list.
Dim _Employee As New Employee()
_Employee.EmployeeLastName = "(Please Select)"
_Employee.EmployeeFirstName = ""
_List.Insert(0, _Employee)

'4) Project list with concatenated field.
Dim _QueryWithSelect As IEnumerable = _
(From xyz In _List _
Select xyz.EmployeeId, _
EmployeeName = xyz.EmployeeLastName & ", " & _
xyz.EmployeeFirstName).ToList()

'5) Return.
Return _QueryWithSelect
***************************************************

I think I need to insert the (Please Select) record after the object with
the concatenated "EmployeeName" has been created, but I'm not sure how.

Thanks for any help,
Ron
Rory Becker - 02 Mar 2008 12:22 GMT
Hello Ronald,
I'm not entirely sure I understand you.

I think you should not add "Please select" to the list at all.

It is better that the thing which uses you IEnumerable add this to whatever
interface you are providing.

Doe shtis make sense?

--
Rory
Ronald S. Cook - 02 Mar 2008 14:45 GMT
Even if I do it in the client, I still need to add that (Please Select) to
the top as is what is needed in our comboboxes.

Any idea how I can do it?

Thanks.

> Hello Ronald,
> I'm not entirely sure I understand you.
[quoted text clipped - 6 lines]
> --
> Rory
Rory Becker - 02 Mar 2008 15:36 GMT
Hello Ronald,

> Even if I do it in the client, I still need to add that (Please
> Select) to the top as is what is needed in our comboboxes.
>
> Any idea how I can do it?

Well you return the List/IEnumerable of the (Employee)items you would have
the client pick from.

You then interate through these items adding them to the combobox.

You can then insert the item you wish as an instruction as the first item.
(Although I would set selectedindex = -1 instead)

The key here is to seperate the additions as the comma is being added due
to processing which was meant for items which are of the Employee type. (Please
Select) is not a real employee and should not suffer the same processing.

--
Rory
Ronald S. Cook - 02 Mar 2008 19:04 GMT
Thanks Rory.  Being new to LINQ, I've never iterated over an IEnumerble.
Can you give me any little snippet that could get me started?

Thanks!
Ron

> Hello Ronald,
>
[quoted text clipped - 17 lines]
> --
> Rory
Rory Becker - 03 Mar 2008 12:11 GMT
Ronald:
> Thanks Rory.  Being new to LINQ, I've never iterated over an
> IEnumerble. Can you give me any little snippet that could get me
> started?

Not sure what you mean here. Linq isn't entirely relavent

You can for each through anything which is IEnumerable

For Each Item as Employee in SomeThingWhichIsIEnumberableOfEmployee
' Do Stuff with Item here. Probably add it to a ddList
Next  

--
Rory

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.