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


ADVERTISEMENT

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

Checking For Null Return?

Nov 14, 2011

ve a simple vb code similar to the below,

Function getvalue (ByVal Val as double) As string
Dim Num as Integer
Dim Prd as double

[code].....

View 4 Replies

Sql - Return A Value To A Sqldatareader If Value Is Null?

Oct 3, 2009

I am currently using a sql data reader (in vb.net) to extract an article object via a stored proc from a SQL Server 2008 database. Part of this object includes the two properties shown below:

theArticle.Truthfulness = ((myReader.GetInt32(myReader.GetOrdinal("Truthfulness"))))
theArticle.Relevance = ((myReader.GetInt32(myReader.GetOrdinal("Relevance"))))

My problem is that the Truthfulness and Relevance may return a null value and this is causing the function to fall over.I think I understand why. I am asking for an integer value (getin32) and because null is returned it fails.How do I accommodate the null value from the database so it does not fall over?

View 5 Replies

Encounter Occurs When Return NULL Value To The Textbox?

Mar 29, 2009

i am retrieving data using data reader. Whenever a null value fetches from the column, the compiler encountering an error. The error occurs when column value contains NULL. I am using Visual Basic 2005.

Please look at the following error which is in red color:

DEVNA11.Checked = IIf(IsDBNull(dr("dev_serv_desc_final_na")), 0, dr("dev_serv_desc_final_na"))
txtPlanServDesFinal.Text = IIf(IsDate(dr("dev_serv_desc_final_planned")), Format(dr("dev_serv_desc_final_planned"), "dd/MM/yyy"), dr("dev_serv_desc_final_planned"))
System.ArgumentException: Argument 'Expression' is not a valid value.

View 3 Replies

Expect The IsInterned Method To Return Null?

Feb 9, 2012

Take the below example. I would expect the IsInterned method to return null, because this string can't possibly be in the intern pool having started up the test app for the first time? I would also expect, that if I did something like string.intern("this112233StringCan'tPossiblyBeInTheInternPool!£$%") first, then this would legitimately be returned by IsInterned from the pool. I've also done the same in c# and the behaviour is the same.

Whenever I use strings in code, I tend to do something like textbox.text = string.intern("someValue") etc or if (textbox.text = "someValue") etc. Infact, whever strings are being used, I've gotten in to the habbit of using string.intern. Is this a bad habbit rather than using constants or the resources file?

[Code]...

View 19 Replies

Using LINQ To Return Element In Collection, Would Like To Return Nothing If Element Not Found?

Mar 3, 2011

I would like the following function to return Nothing if the element with the specified key is not in the collection. Instead, it returns an error - something to the effect of "no element found"

Public Class MyCollection
Inherits System.Collections.ObjectModel.Collection(Of MyType)
Public Function FindByActivityKey(ByVal searchValue As Integer) As MyType

[code]....

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

Allow Null Values, And Return A String To The User If No Date If Specified?

Mar 9, 2010

I want to create a custom date type. I want to allow null values, and return a string to the user if no date if specified.

View 13 Replies

How To Deal With Execute Scalar Command That Return Null

Jan 10, 2012

I want to retrieve total value from sales table in sqlcommand object. Below is my sample code.I will get error if there was no data in the tabel that matched my query saying that null could not be converted into decimal.

I would not get error if there was data that matched my query and returned the total value in tmpSales variable.My question is what is the best way to deal with this situation?

Dim CmdTmp As System.Data.SqlClient.SqlCommand

Dim tmpSales As Decimal

CmdSales = New System.Data.SqlClient.SqlCommand("SELECT SUM(Total) FROM Sales WHERE Date>= '1 Jan 2011' And Date<= '30 Jan 2011", ConDB)tmpSales = CmdSales.ExecuteScalar

View 2 Replies

Return Null Values In Short Circuit If Statement?

Jul 1, 2011

How can i return null values in if statement above. This statement is not working if condtion is false its retruning me 0 value even if condition is false

dim d as nullable(0f Decimal)
d=(if(_dr("value") isnot dbnull.value,Convert.toDecimal((_dr("value")),Nothing)

View 6 Replies

VS 2008 Datetime Picker And Combo Box Return Null

Jul 14, 2009

I have a datetimepicker and combobox on my form. If a user does not change the date on dtpicker or does not change text on combo box, these controls return null value, and the save operation fails. The controls are bound to data in a database.

View 1 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

Apr 20, 2010

I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).

It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.

For example... I write this:

[CODE]....................

Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.

So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.

View 2 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

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

[VB 2010] Return Alert Message If SQL Query Return No Records

Dec 12, 2011

I use this code to return records in a DataGridView:

[Code]....

View 3 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 + 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

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

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

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

How To Return Firstchild Value In LINQ

Apr 20, 2012

Using LINQ, How do I only get the author element value for the following XML: [code]but n.value returns the author and all the child element values.

View 3 Replies

Return Max Value With LINQ Query?

Nov 3, 2011

I have a method that takes in an id, a start date, and and end date as parameters. It will return rows of data each corresponding to the day of the week that fall between the date range. The rows are all doubles. After returning it into a DataTable, I need to be able to use LINQ in VB.NET to return the maximum value. How can I achieve this? Here is the initial setup?

[Code]...

View 1 Replies

Use Linq To Return A Row In A DataTable?

Jan 24, 2012

Currently, I am using a loop to find the row I want to update.

Public Sub pubsub_SetUserDGVColumnWidth(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs)
' update all user settings for the given column

[Code]....

View 8 Replies

LINQ To Entities .Any() Results In Null Reference Exception?

Nov 16, 2011

I have a simple query as below:

Dim sizings = From a In db.Sizings
Where a.Customer.ID = customer.ID
Select a
If sizings.Any Then
.....

The sizings.Any line is throwing a null reference exception. I thought I was meant to use .Any to determine if there were any rows returned?isnothing(sizings) returns false.

Edit - Resolution:Don't use null objects in the LINQ Query!

View 2 Replies

Return LINQ Results From Function?

Jun 10, 2012

I'm trying to return a single object from an array of objects with linq.[code]...

View 2 Replies

Asp.net - Return Two Tables From A Stored Procedure From LINQ To SQL?

Aug 4, 2011

I have written a stored procedure like this:

CREATE PROCEDURE [dbo].[TestProcedure]
AS
BEGIN
SELECT TOP 1 CampaignID FROM Campaigns
SELECT TOP 1 ServiceID FROM Services ORDER BY ServiceID desc
END

In my .NET Project, I have a LINQ to SQL file (.dbml) and I have drag-and-dropped this procedure to create a new class TestProcedureResult:

Partial Public Class TestProcedureResult
Private _CampaignID As Integer
Public Sub New()

[Code]....

So it is not returning ServiceID. How can I retreive ServiceID using LINQ to SQL? I know we can customize stored procedure calls, but how can I customize in this particular scenario?

View 1 Replies







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