Filtering A Collection With Linq And Multiple Criteria?
Jun 7, 2012
On my view there is a datatable holding a collection of ServerRow and 4 textboxes (Hostname, OS, Location, Zone). When the user types into any of the 4 boxes I want to immediately filter this list. I have this code setup and ready to go that on the set method of each textbox property I call the filter method.
Now onto the problem: if I have 4 criteria that means I have 2 to the power of 4 different scenarios. What I would like to do is write a linq statement with all of these scenarios dealt with such that if any of the properties are NullOrEmpty they will not be used in the Where clause and on the flip side if there is a value the corresponding field will be searched with a Contains.
Example
AvailableCis = New ObservableCollection(Of ServerRow)
(_CiData.Where(Function(ci) ci.OS.ToUpper
.Equals(_selectedOS.ToUpper) AndAlso
ci.HostName.ToUpper.Contains(_ciNameFilterText.ToUpper))
.OrderBy(Function(a) a.CiName))
This example shows how it works with 2 criteria and both of those criteria are set.
View 1 Replies
ADVERTISEMENT
Mar 9, 2012
I have a datatable as shown in the figure. Let me explain my required based on this image. I have 7 rows of data. The rows 1 and 2 contains columns till UnitSqcNo same. I want only row 3 among the two. In general I want select all the rows with distinct model, unittype, unit and rest with greater CompId. ie the table should look like
View 1 Replies
Jun 28, 2010
I have a question about binding the datasource (MS Access database) to a listbox in a VB form. I have created a listbox and in the datasources explorer I have my datasource say SampleDS. I have several columns inside my datasource, say name, age, address in it. If I select name and drag to the listobx in the form, only the entries in the name column will be displayed in the listbox.
I want to know how to filter the name based on criteria. For example, how do I display names whose age >25?
View 1 Replies
Apr 15, 2009
I've got the following ADO.NET Entity Framework Entity Data Model:I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.
This LINQ Does Not Work:
Dim ServicesId As Integer = ...
Dim KeywordStatus As Integer = ...
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p
The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.
[Code]...
View 1 Replies
Apr 15, 2011
search the collection of a collection in my LINQ Where clause?
View 11 Replies
Mar 8, 2010
Why does the following query raise the error below for a row with a NULL value for barrel when I explicitly filter out those rows in the Where clause?
Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
Where Not IsDBNull(row.Cal) AndAlso tiCal_drop.Text = row.Cal _
AndAlso Not IsDBNull(row.Tran) AndAlso tiTrans_drop.Text = row.Tran _
[code]....
Run-time exception thrown : System.Data.StrongTypingException - The value for column 'barrel' in table 'conformal' is DBNull.
How should my query / condition be rewritten to work as I intended?
View 2 Replies
Nov 17, 2009
I am struggling with a nullable datetime column [DateInsp] in an ASP.NET app which uses SubSonic3, Linq, MS SQL Server 2005.I had this all working when the datetime column [DateInsp] did not allow nulls. A new requirement forced me to set the [DateInsp] column to allow nulls and now I am struggling getting this piece of functionality to work properly again.
Problem 1:I need to first render a dropdown list of the 7 most recent inspection dates for a given inspector (this is a grouped list of the 7 most recent dates for the inspector). Here is the TSQL that I need to convert to Linq syntax:
declare @InspectorID varchar(5)
set @InspectorID = 'GPA'
select top 7 convert(nvarchar(30), [DateInsp], 101) InspectedDate
[code]....
If I can't get this work properly using Linq, BUT I can/could build a stored proc to return the list of dates and throw that into a dropdown. Fair enough. I've been fighting with the Linq syntax?
Problem 2: I need to use the selected date in the dropdown mentioned above to pull the correct records for this inspector and the correct date. Again, this is a nullable datetime field and this is real sticking point for me.
Here was the original Linq syntax that accomplished the requirement before I had to change the datetime field to allow Nulls:
Dim query = (From i In db.IncomingInspections _
Where i.InspectorID = User.Identity.Name _
Group By Key = New With {i.DateInsp} Into Group _
[code]....
For some reason I can't use the .Value property; I get: The member 'Value' is not supported I get: "Incorrect syntax near '<'." if I try to add the date comparison to the where clause too.
View 2 Replies
Apr 13, 2011
I am using LINQ - VB.Net I want to filter my List object by passing String object in the where.
Dim _permittedTransactionCodes As List(Of String) = Nothing 'String object
it is populated with data.
Dim tap100transCodeInfos As List(Of Tap100transCodeInfo) = _dal.GetActiveTap100transCodeByHdrScreenCde(UCase(screenId), "TRAN_CDE")
i am trying something below, but not getting the filtered results
tap100transCodeInfos.Where(Function(x) _permittedTransactionCodes.Contains(x.TranCde))
View 1 Replies
Mar 1, 2011
I have list object and I need to check id in a comma separated string using LINQ in VB.NET, something like this:
dim strId as String = "1,2,3,5,"
dim myList = from objmylist where objmylist.id in (strId)
View 4 Replies
Apr 14, 2011
Take the following scenario:
Public Class Store
Public Overridable Property Areas As List(Of Area)
End Class
Public Class Area
[code]....
What's the quickest way to get a total count of shelves for a store? I.e. for a store I get the total count of areas by using Areas.Count Or will I need to loop through each area and tally the count of shelves?
View 2 Replies
Apr 24, 2009
I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows:
grid.DataSource = myEntities.entityName.Where("it.field = " & field)
It works, but it obviously isn't strongly typed. Is there a way to define the Where clause of an entity using a strongly typed notation?
View 1 Replies
May 27, 2011
I am doing a simple database project.I need to give the input in the database which is an access db from my input form and i have managed to do this part right.then i need to retrieve the details from the db using multiple search fields and show them in the datagrid view.I have 8 search fields(5 textboxes and 3 combo boxes). I also have included 4 other buttons which respectively clears the search boxes;clear the results of the gridview; show all results from the database;go to the input form and offcourse 1 search button.now all the buttons working fine except the search button. actually when i click on the search button if i include sql query for all the search fields only the first one works and also if i have clicked any other buttons before clicking the search button nothing happens, no result is shown and it happens the same if i search once and clicked any other buttons and come back to search, no result. I need to show the results in the gridview depending on the user input on those search criterias. user should be able to search in any combinations.I am using the below codings in my search form. the combo boxes are not bound.datagrid is bound to database though.
Public Class Paxsearchfrm
Private Sub Paxsearchfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LAFDataSet.Table1' table. You can move, or remove it, as needed.
End Sub
[code]....
View 9 Replies
May 14, 2012
I am trying to filter a list of (t) by multiple criteria. here is what i have:
[Code]....
I now want to filter this list by myObject's various properties. Heres the problem:
1. A user should be able to either filter on one specific custName or remove the filter for this property AND
2. A user should be able to either filter on one specific notificationDate or remove the filter for this propertyl AND
3. A user should be able to either filter on one specific materialType or remove the filter for this property
I know I can just write a lot of if..then but i'm looking for a more elegant solution.
View 1 Replies
Apr 14, 2009
I have a code to search through a listbox with mutiple search criteria. Here is the code:[code]When I search for something, how do I make sure I do not obtain 2 of the same results, If both criteria are found, or if all three are found?
View 4 Replies
May 21, 2012
Currently I am searching through my list to find Customers that match on Address.
I need to match on both address and city. How do I rewrite my lambda Expression to match both criteria?
CustomerList.FindAll(Function(c) c.Address = addressToMatch)
View 1 Replies
Mar 21, 2012
[code]the main piece deals with the binding source filter. I've tried or/and. i tried to include that both codes in the string. i don't know what to do again i know you would recommend SQL but i don't know how to use that yet, so could you please recommend some bindingsourcefilter code to assist please. Its for a School project the search window looks like the attached picture
View 13 Replies
Jun 28, 2010
how can i get the illegal character in a string
for example
dim Strto_check as string = "1+2-2"
dim Listof_Illegalstrings = "~!@#$%^&*()_-+=-?/.,><|" ""
now i want a function to find out which is the invalid character available in the strto_check variable and then replace it with a standard place holder
View 7 Replies
Feb 28, 2012
I have a strongly-typed datasets created using VS data designers. In this dataset I have 3 main tables:
Patients
Users (Relationship: Users.ClinicianId > Patients.ClinicianId)
SchedAppointments
Issue is I would like to filter the datasets based the user type and a few other ways. How can I filter each table(sql query) using the BindingSource that was automatically added. I thought I read that some of the functions work against the current datamember, so I tried the following code.
WAMMTPTrackerDataSet1BindingSource.DataMember = "Patients"
WAMMTPTrackerDataSet1BindingSource.Filter = "ClinicianId = " & gClinicianId
'Users
[Code].....
It appears that what I read was either very old or never worked that way. what is the best way to handle with with a typed dataset?
View 1 Replies
Mar 22, 2009
this is the wrong forum because I am quite new to this :S and I am actually unsure what this fits under. I am using Visual Studio 2008 windows form in .vb so I am taking a guess at it being Visual Basic 6.0Well the question is this. On a form I have 3 Datagrids. The first one shows information about a case including client name and ID. The second shows a table that contains all the jobs registered to the company by the clients. lient can have up to 8 Jobs. The third is a list of all case numbers that clients have
View 4 Replies
Mar 25, 2012
I am working on a utility to reformat a text file. Working on language to remove duplicate record entries. However there are desirable ("keeper") duplicates and then those I want to remove. I handled the problem by temporarily assigning a unique number to each @D line, then stripping them off after I've removed duplicates. So far so good, except in removing unwanted duplicates I have an extra of the "keeper" duplicates left that doesn't get removed. See below. I am wondering if there is a way to search for a line in a textbox starting with a certain character, but is also proceeded by 2 blank lines and followed by 1 blank line. CODE IM USING TO REMOVE DUPS yet keep formatting with blank line separators, etc.:
[Code]...
View 5 Replies
Dec 16, 2011
How can i make a multiple filtering in datagrid view
View 1 Replies
Jul 13, 2010
Using the below code, allows me to filter a data (from the same table) in a database using checkboxes & their Tag property.
Public Class Form1
Private checkBoxes As CheckBox()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
[Code]....
Since certain movies can belong to multiple genres & vise versa, I'm trying to alter the code listed above to filter all movies belonging to a certain genre using the GenreID found in the joint table.
Is this possible or do I need to go about this in a different way?
View 14 Replies
Aug 18, 2009
I would like to query an Employee by matching First and Last name. Ideally, I'd like to be able to specify that in one EmployeeQueryRq QBFC object.
I think I have a start:
Dim EmployeeQueryRq As IEmployeeQuery
EmployeeQueryRq = requestMsgSet.AppendEmployeeQueryRq()
EmployeeQueryRq.ORListQuery.ListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains)
EmployeeQueryRq.ORListQuery.ListFilter.ORNameFilter.NameFilter.Name.SetValue(LastName)
Is there any way I can add an additional NameFilter to the same request? Or am I stuck walking a response list for the other criteria (albeit a smaller one limited to containing at least one value)?
View 1 Replies
Apr 22, 2011
Ok so basically heres what i need to do: Extract text from the webpage that meets a certain criteria. There will be a ton of these on 1 page and i would like to add them to a rich textbox on sperate lines.
I know that it needs to be in a loop and its needs to Parse the wepage(Dim web1 As String = Me.WebBrowser1.Document.Body.InnerText)
The criteria is: Starts with 1 to 4(random) integers, Followed by "my" then 13(random) numbers and letters. Or if it starts with "167my" + 6(random) number and letters.
Edit: Also im going to try to make it loop through a list of webpages to do this.
View 5 Replies
Jan 23, 2012
Well I have a list of things I want to search based on multiple points of data...for example Resolution, 3D capable, touchscreen capable....etc....What is the best way for display someone can think of & filtering results by capability, I have none of it typed out, etc...like list of objects & capabilities, etc... alreat...so it can be made any way that is thought to be good(with speed as well) for many different listings...say 1,000 of them & it filters pretty much instantly....reading capabilities & such & the list itself is easy but how can I make a filter(unchecking something brings back things, checking something takes away only since well your adding capabilities to filter selection....I have pictures that can go with items too as well as a name & more information could be given directly with the method or clicking on the picture/item.
View 13 Replies
Sep 8, 2010
Here is an example of my xml doc:
<?xml version="1.0" encoding="utf-8"?>
<employeedata>
<employee>
<firstname>Bob</firstname>
<lastname>Anderson</lastname>
[Code]...
However, only the first phone number (Office) displays in the listbox. The phoneinfo collection has both <phone> elements, but the For Each statement doesn't seem to iterate thru.
View 8 Replies
Mar 28, 2012
I have a Customer object which has a collection of ContactNumbers. Is it possible with LINQ to get a list of Customers where one of the contact numbers = '123'?
Public Class Customer
Public Overridable Property ContactNumbers As List(Of ContactNumber)
End Class
[Code].....
View 1 Replies
Oct 8, 2009
I'm building flat file content from collections of strings.
Example collection: A, B, C, D, E, etc.
I want to be able to output these values to a string with line feeds in one swoop with Linq if possible.[cod]e...
View 8 Replies
Mar 6, 2012
How to get the last instance of label control in List (of Control) using linq?
View 4 Replies
Jun 29, 2009
Private Function GetWebDataGridOKButtonId() As String
Dim ctls As ControlCollection = _
WebDataGrid1.Controls(0).Controls(0).Controls
[Code]....
This is not working for me. I am trying to iterate a control collection and return one control ID.
View 2 Replies