LINQ + Find Count Of Non-null Values

Apr 2, 2010

I have a table with the below structure.

ID VALUE
1 3.2
2 NULL
4 NULL
5 NULL
7 NULL
10 1.8
11 NULL
12 3.2
15 4.7
17 NULL
22 NULL
24 NULL
25 NULL
27 NULL
28 7

I would like to get the max count of consecutive null values in the table.

View 3 Replies


ADVERTISEMENT

VS 2008 Count(*) Does Not Work For Null Values

Feb 15, 2010

i m trying to run a query on an MSAccess table, but it does not give me any count but only 0.

There are 3 null values which i should be getting but it does not give me the result. This query works perfectly in MSSql Server 2008.

the query is :

Quote:

SELECT COUNT(*) AS Cntr
FROM (Modul m LEFT OUTER JOIN
Relation r ON m.Mod_Name = r.von)
WHERE (m.[group] = '')

I need a workaround for this but am unable to find one.

View 2 Replies

Linq To Find List With Largest Count

Aug 9, 2010

I am learning Linq, so bear with me. I have a class object that holds 4 other class objects with each holding a List(Of T) of the next. Think tiered classes. As these lists as built I need to search all the Group2 for all Group3 to see which Group3.units.count is the largest. "units" being a List(Of T). [code]

View 4 Replies

Linq Query Handling Null Values?

Nov 12, 2011

From r In ReceiptLines
Where
r.RECEIPT.RECEIPTDATE >= _reportStartDate
And r.RECEIPT.RECEIPTDATE <= _reportEndDate

[Code].....

I am fetching all departments and their sales, average, count from the ReceiptLine, Receipt, ReceiptDiscount tables. The problem i am facing is, if i remove where discount > 0, I am getting null exception. But if I include that, then I only get sales that has discount. How would I write query that bring all sales less discount (if it has one).

View 2 Replies

Linq To Datasets Null Values On Integers?

Feb 21, 2010

If I have a datatble column set as int16 but rows can contain null values for this column. How do i write the linq query. I keep getting an error null value exception. Dim query = From n In resultstable.AsEnumerable Where n.value is dbnull.value does n't work.

View 6 Replies

Using LINQ To Find Unique Values In A List Of Objects?

Jul 3, 2011

I am having so trouble with the ToUpper() procedure with strings. I am using LINQ to find unique values in a list of objects. In that whole process I set the values to compare to all lowercase in order to get a proper list. My goal is to populate a dropdown list with the values. I'm attempting to set the first letter of of the string to uppercase and keep the rest lowercase however the toUpper() procedure is not working?

Private Function FixCase(ByVal strIn) As String
Dim strOutput As String
Dim intStringLength As Integer = strIn.Length - 1
strOutput = strIn.Substring(0, 1)

[code].....

View 5 Replies

Linq To Sql Null - Check Whether A Column Is Null

Jul 15, 2011

How to check whether a column is null i use the following code but I got this error "Input string was not in a correct format."

[Code]....

View 2 Replies

Null Reference In Lambda Max Count?

Oct 5, 2011

Public Class Inventory
Public Property Productcode As String
Public Property lstattribute As List(Of Attribute)[code]....

I have a list of inventory items.I am trying to get the max count of attributelist in the inventory list .I used this code

oLsInventory.OrderByDescending(Function(c) c.AttributeList.Count).FirstOrDefault().AttributeList.Count

But if my attribute list null. The lambda throws null reference.Is there any way to check for null reference in lambda ? Or is there a better way to rewrite the above linq query ?

View 3 Replies

IEnumerable Not Null But Calling Count Results In Exception

Jun 2, 2010

I have code that's working beautifully on my development machine, but when deployed to the server is throwing null reference exception. So, I can't step through the code, but I've pinned down the culprit. But now I am puzzled.[code]In the code above persons is a dictionary of custom class, and certs is of IEnumerable type. Now here's the quandary.. The first line that sets the label returns False, so certs is not null. But the second line throws an null reference exception.

View 1 Replies

C# - LINQ To SQL Sum Null Value?

Aug 20, 2010

I have the following query, I'd like to sum the NULL value also. Some TimeSheet don't records in TimeRecord and some tr.TimeIn and tr.TimeOut are NULL.The query select only TimeSheet that has reords in TimeRecord. How I can have it select everything, and sum up the NULL value as well. So, the SUM of NULL will be just zero.

[Code]...

View 1 Replies

Xml - Mix Values From Local Data With Values Returned From Database While Using LINQ To SQL?

Oct 27, 2010

I am creating an xml file with LINQ as follows...

Public Sub CreateXml()
Dim db As New MDataContext
Dim Customers = <gallery columns="3" rows="3">

[code]....

Could i mix local values with the ones returned from the LINQ query...Something like the following?

Public Sub CreateXml(ByVal **Col** As String, ByVal **Row** As String)
Dim db As New MDataContext
Dim Customers = <gallery columns="& **Col** &" rows="& **Row** &">

[code]...

View 1 Replies

Null Result In LINQ?

Apr 11, 2012

I'm having trouble with a null result, when I compare the query it said I cant it give the following error "sequence contains no elements"

Dim existe = (
p In abc.Ventadetalles
Where p.idarticulo = txtArticulo.Text

[code].....

View 3 Replies

C# - LINQ To SQL Count Table With Relationship

Jun 17, 2011

C# or VB.NET is fine. I'd like to count number of people for each country from the following tables with LINQ to SQL I have two tables, one is Countries and other is People. It's one to many relatoionship from Countries to People. ountries table column:CountryId,CountryName People:PeopleId,FullName,CountryId (a primary key from Country table and allowed null) I want to count how many people each country has and get something like the following result that shows only the country that has people. Because there are some countries that have no people in the People table.

[Code]...

View 2 Replies

Get The Count From A Query Expression In Linq?

Jan 25, 2012

What I have right now is this:

Dim users = From users In tempTable _
Distinct Select users.Item("s_userid")
Dim usersCount As Integer = users.Count

But I pretty sure I shouldn't have to do that. I should be able to get the count in/from that first linq query.

View 2 Replies

Linq Group Count Items?

Dec 5, 2011

I have this linq to entity

From r In ReceiptRepository.Fetch
Where
r.RECEIPTDATE >= ReportStartDate And

[Code]....

This is working fine, except the count property, it is just giving the number of group count. I don't know how to find out each Tender Count

View 1 Replies

LINQ To SQL Using GROUP BY And COUNT(DISTINCT)

Jan 15, 2009

I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr)
from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query

[Code]...

View 5 Replies

Linq-to-sql Speed When Getting Table Count?

Mar 31, 2012

Dim mydata = (From c In dc.Table Select New With {c.ID}).Count
any faster than this:
Dim mydata = (From c In dc.Table Select c).Count

[code].....

View 1 Replies

Using Linq Count Function With Datatable?

Aug 2, 2011

I write the code below. I want to make short using linq count.

Dim query0 = From obj In dtAginglist _
Where (obj.Field(Of String)("CurrentStatus") = "Open" Or obj.Field(Of String)("CurrentStatus") = "Acknowledge") _

[Code]....

I try to use code below but it dosen't work with if source is datatable.

Dim orderCounts = From c In customers New With { _
c.CustomerID, Key .OrderCount = c.Orders.Count() }

View 1 Replies

Handle Null In LINQ Subquery?

May 24, 2009

I've got a subquery that returns the most recent value from a child table. In some cases the subquery returns nothing. The query below fails at runtime because the inferred type of MemberPrice is decimal and is not nullable. [code]...

View 4 Replies

Linq To XML Remove Element Where Value Is Null?

Apr 19, 2011

I have a XML xElement like[code]...

In order to get rid of Trick nodes where value is null, I wrote:

myXmlElement.<Play>.<Trick>.Where(Function(m) m.<Trick>.Value = "").Remove()

View 4 Replies

VS 2010 LINQ Null Return?

Dec 2, 2011

I'm having trouble figuring out what to do with the bolded part, when there are no nodes to return.If there are no image tags inside the <images> tag, i get an "Object reference is not set to an instance of an object".I have been searching and searching for an answer but can't find one.

Dim orders = From o In xmlLinq.Descendants("order")
Select New With { _
.orderID = o.Attribute("id").Value, _

[code].....

View 2 Replies

Linq Distinct Count Multiple Fields

Mar 24, 2012

I have a Table:

[Code]...

I'm trying by LINQ-query (VB.NET) to return a count for distinct value of Objects, Stuffs and Colours for every Room:

[Code]...

View 1 Replies

Return Max Record Count By Grouping In Linq?

Nov 9, 2011

I'm very new to linq and I'm trying to come up with a linq query against a dataset that will return a max count value based on grouping records.[code]...

View 1 Replies

.net - LINQ Null Date Comparison In Dataset?

Aug 26, 2011

I have a DataSet where I need to filter the collection where one of the date columns is not null.

How do you term this in LINQ?

This is what I have so far but there is a compiler error on the w.CompletedDate field in the Where clause.

Dim completed = From ins In InspectionDataset.Inspection.AsEnumerable _
Where (Function(w) w.CompletedDate IsNot Nothing) _
Order By ins.Field(Of DateTime)("UpdatedDate")

I have also tried it the below way but the compiler will not allow the DBNull comparison.

Dim completed = From ins In Inspection.AsEnumerable _
Where ins.Field(Of DateTime)("CompletedDate") <> DBNull.Value _
Order By ins.Field(Of DateTime)("UpdatedDate")

View 1 Replies

Linq Expression Returning Null Rather Than Empty Set

Nov 18, 2010

I am finding this weird issue. When I do this > activities.Where(Function(a) (Not a.IsDeleted And a.ParentId = 100) It returns an in-memory query & when I try opening it up, it throws a object not set exception. This only happens when there were no items which satisfied the condition. Shouldn't it be returning an empty set? When there are items satisfying the condition, then it returns a list & works all good.

View 1 Replies

Linq Left Outer Join Null

Sep 27, 2010

I've got what I think is a working left outer join linq query but I'm having problems with the select because of null values in the right hand side of the join.[code]I want to return all of e and one column from c called tClassCode. I was wondering what the syntax would be. As you can see I'm using vb.net.[code]If i remove the c.tClassCode from the select the query runs without error. So i though perhaps i needed to do a select new but i don't think i was doing that correctly either.

View 2 Replies

Select All Records Where A Field Is Null Using LINQ?

Jan 25, 2012

I've got a table that caches calculated values for certain dates. I want to use LINQ to select all rows where the calculated value fields are null.But when I use isNothing I get an error that LINQ can't translate this into T-SQL. Is there a way to select null values with link, like this...?

Dim var = From rec As Record In myDataContext.Records Where IsNothing(rec.calculatedValue) Select rec

Other posts on stackoverflow mostly discuss how to avoid or check for null values with LINQ.

Note: I can't just set cacluatedValue's default to -1 to flag records whose calculated value has not been set (and then select those records) because I run queries that sum/average the calculated values. Selecting nulls seems cleaner and less bug-prone.

View 1 Replies

.net - Use LINQ To Count The Number Of Combinations Existing In Two Lists?

Jun 17, 2010

I'm trying to create a LINQ query (or queries) that count the total number of occurences of a combinations of items in one list that exist in a different list. For example, take the following lists:

CartItems DiscountItems
========= =============
AAA AAA

[code]....

The result of the query operation should be 2 since I can find two combinations of AAA and BBB (from DiscountItems) within the contents of CartItems.My thinking in approaching the query is to join the lists together to shorten CartItems to only include items from DiscountItems. The solution would be to find the CartItem in the resulting query that occurs the least amount of times, thus indicating how many combinations of items exist in CartItems.When CartItems is filtered to only the items in DiscountItems, it can be visually displayed like this:

CartItems that get a discount
=============================
AAA BBB <= This combination is eligible for a discount
AAA BBB <= This combination is eligible for a discount
AAA <= Not eligible

Thus, because there are 2 combinations of the discount in the Cart, the result is 2.Here's the query I already have, but it's not working. query results in an enumeration with 100 items, far more than I expected.

Dim query = From cartItem In Cart.CartItems
Group Join discountItem
In DiscountGroup.DiscountItems

[code]....

View 2 Replies

C# - LINQ To SQL To Query Parent And Count Childs In Hierarchy?

Dec 8, 2010

I'd take both C# and VB.NET suggestion.I'm using LINQ to query data. I'm trying to query the parent and count the child tags.Here's my Tags table column:

TagId (int primary)
TagName
ParentId (int Allow NULL referred to TagId column)

Here's some sample data:

[Code]...

View 3 Replies

LINQ - Query Children Object If Parent Count Is = 1

Apr 17, 2012

I have a the following Class structure. Company > List(of Departments) > List(of Employees) I want to Query a Company to find out if it has a department of the following name and a Employee in that department with the following ID! How could I query this. The way I have the code it expect to return one department so I have it doing

[Code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved