score:1
Accepted answer
If searchtype = "withdatetime" Then
Dim locs As New crimemsapslocationDataContext
Dim giveloc = From locations In locs.crimelocations _
Where locations.INCIDENTTYPE = crime And (locations.DATE_COMTD >= Convert.ToDateTime(startdate) And locations.DATE_COMTD <= Convert.ToDateTime(enddate)) _
And (locations.gettimecom >= starttime And locations.gettimecom <= endtime) _
Select locations
Return giveloc.ToList
ElseIf searchtype = "withdate" Then
Dim locs As New crimemsapslocationDataContext
Dim giveloc = From locations In locs.crimelocations _
Where locations.INCIDENTTYPE = crime And (locations.DATE_COMTD >= Convert.ToDateTime(startdate) And locations.DATE_COMTD <= Convert.ToDateTime(enddate)) _
Select locations
Return giveloc.ToList
ElseIf searchtype = "without" Then
Dim locs As New crimemsapslocationDataContext
Dim giveloc = From locations In locs.crimelocations _
Where locations.INCIDENTTYPE = crime _
Select locations
Return giveloc.ToList
End If
// if none of the if-else conditions are met your code goes straight to here and there is not return statement
Return null; // this fixes it.
Source: stackoverflow.com
Related Query
- LINQ function to return list but compiler says function doesn't return a value on all code path
- How can I use LINQ to return a list of Countries but place a particular country aribitrarly at the top?
- C# return value inside linq list based on if statement
- Return list with more than one value stored in a dictionary using linq
- Return a value when the element is not present in list using linq
- How can I return a list or enumerable of rows where column value has changed with Linq
- Using Linq Except to return items deleted from a list but have the same Id
- How to use the return value of a function in a linq where clause?
- Construct a LINQ query to return an item from a List that is related by one property to other members but which differs by a second property
- LINQ Query search List within another List and return value
- return list from linq function
- How to write a LINQ to return results only if value is present in a pre-definded list
- C# Linq to check if the given list of string is available in either (oldNumber and newNumber) of the Column and return only the matched cell value
- LINQ lookup if table column contains value and return list of objects
- Searching if value exists in a list of objects using Linq
- How can I get LINQ to return the object which has the max value for a given property?
- How to check if all list items have the same value and return it, or return an “otherValue” if they don’t?
- LINQ - Convert List to Dictionary with Value as List
- LINQ query to return distinct field values from list of objects
- Return list using select new in LINQ
- Return list of specific property of object using linq
- Is there a LINQ function for getting the longest string in a list of strings?
- compare two list and return not matching items using linq
- LINQ return items in a List that matches any Names (string) in another list
- Using LINQ to find item in a List but get "Value cannot be null. Parameter name: source"
- C# LINQ select from where value is not contained in array / list
- Filter linq list on property value
- Simplest way to filter value from generic List in C# using LINQ
- Return null instead default value in LINQ
- How to update value in a List using LINQ
More Query from same tag
- Split duplicates in lists using LINQ
- LINQ - Fetch items from list starting from specific index
- Reading values from a DataTable column into a List<string> with LINQ
- Group By Users and show DETAILED results for every week day
- How to have a where clause on an insert or an update in Linq to Sql?
- How to retrieve different object types from IQueryable
- Order by bigger of two Sql columns
- LINQ Unable to get distinct value from many to many Entity Framework
- Writing out 'AND' and 'OR' in LINQ
- Problems using linq in order to find differences in datatables
- Why does an IF Statement effect the outcome of my LINQ Statement?
- LINQ .ToDictionary for 2d dictionary
- How to write this Linq-to-SQL select query
- How do I navigate through multiple relationships using LINQ to Entities?
- C# Linq GroupBy ==> Class vs Anonymous class --- different result
- "There is already an open datareader associated with this command" - even when using Include()
- linq .sum request exception
- What is the regex expression that will add some character after my match.Value
- How can I access the group of a linq group-by query from a nested repeater control?
- LINQ and paging with a DataTable - can't get Skip working?
- Delete Duplicates with LINQ in VB. NET
- Is there an "Explain Query" for MongoDB Linq?
- need help around IQueryable query result
- How to pass Expression<Func<T, bool>> predicate as a parameter to a method?
- Can I flatten a List<object> to an anonymous object with properties for each item?
- I have a list of date of birth. I want to convert it by age group. i.e: group-1: age 0 - 15, group 2: age 15 -20 etc
- How does c# interpret my query?
- Linq query with GROUP BY on multiple fields, SUM and COUNT
- how to show image from database in asp:image with linq?
- .net core - combine a list of func with or to a single func