Check Whether Lamda Expressioin Parameters Are Nullable?

Aug 31, 2011

typeof(Nullable<>)
public static bool IsNullableType(Type t)
{
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>);
}

I was using this to check whether Lamda Expressioin parameters are nullable.

View 3 Replies


ADVERTISEMENT

Marking Parameters As Nullable?

Dec 22, 2009

I've picked up some code from a colleague, and in one of his methods he has a boolean parameter: ByVal showProactiveChases As Boolean?. I had to look up the ? operator yesterday to see that it denotes a Nullable type. My question is, if I change it to: ByVal showProactiveChases As Nullable(Of Boolean), does the meaning remain the same? I think provided it doesn't change the meaning the second way is much more readable.

View 4 Replies

C# - Correct Way To Check If Nullable Has A Value?

May 8, 2011

assuming v is a nullable, I'm wondering what are the implications / differences between these usages:

VB:

If v Is Nothing Then
If v.HasValue Then

C#:

if (v == null)
if (!v.HasValue)

View 4 Replies

Can't Seem To Make The Lamda Expression Work?

Aug 12, 2010

I'm trying to convert a function in C# to VB.Net 2008 and can't seem to make the Lamda expression work. The code is taken from a neat little C# SMTP server that saves emails to Azure blob storage

[Code]...

View 3 Replies

Lamda Expressions Are Not Showing Up In Intellesence?

Nov 12, 2010

I am having an strange problem in visual studio 2010, visual basic, and using linq. My lamda expressions are not showing up in intellesence. The project I am working on was created in visual studio 2008 and I have converted it to a visual studio 2010 project.

Here is the expression I am trying to run:

ClockItemsColl.Filter = ClockItemsColl.AsQueryable().OrderBy(d >= d.Second)

However the error I am getting is:

'd' is not accessible in this context because it is 'Friend'.

I have also tried

ClockItemsColl.Filter = ClockItemsColl.AsQueryable().OrderBy(Function(d As ClockItems) d >= d.Second)

But is still generates an error and I can't make heads or tails of it.

Overload resolution failed because no accessible 'OrderBy' can be called with these arguments:
Extension method 'Public Function OrderBy(Of TKey)(keySelector As System.Func(Of BusinessObjects.ClockItems, TKey)) As System.Linq.IOrderedEnumerable(Of BusinessObjects.ClockItems)' defined in 'System.Linq.Enumerable': Operator '>=' is not defined for types 'BusinessObjects.ClockItems' and 'Integer?'.

[code]....

View 1 Replies

Lambda - Type Inferencing In Lamda Expressions?

Feb 22, 2010

I have a type lets call it "MyType". I have a List(Of MyType). Here is what i'm doing: MyList.Sum(Function(x) x.MyFieldToTotal) "MyFieldToTotal" is a decimal. For the life of me i can't figure out why x above is an object rather than a type of "MyType". Shouldn't Type Inferencing be working in this case? Even in intellisense i get "selector as System.Func(Of MyType) as Decimal"

[Code]...

View 1 Replies

Passing Parameters To SQL To Check If User Exists

May 8, 2011

Just have a quick question really, I am just making a simple application that allows me to check if a user exists in SQL here's my code

Public Function Check(ByVal textbox1, ByVal textbox2) As String
Dim comm As New SqlCommand
Dim conn As New SqlConnection
Dim Adap As New SqlDataAdapter
[Code] .....

And when it comes to the Comm line I get this error
Operator '&' is not defined for string "Select * from Login where Userna" and type 'TextBox'.
I've tried removing the "&" and well i cant figure it out.

View 1 Replies

MySQL Parameters / AddWithValue - How To Avoid To Check For Nulls

Sep 15, 2010

Let's say I have a MySql stored procedure that inserts a record with some nullable CHAR fields. In VB.NET if I don't check for Nothing (or Null in other languages), I get an exception from the db driver, so I write:
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("_name", if(name Is Nothing, "", name)).Direction = ParameterDirection.Input;

And this is the first thing I don't like; I'd like to pass Nothing and the driver knows it has to put NULL in the Db. But then, in the stored procedure, I have to check back the field if it is empty:
INSERT INTO mytable
(name, -- other 200 char fields)
VALUES
(NULLIF(_name, ''),
-- other 200 char fields
)

I have to check for nothingness/emptiness twice. Is there a better, more direct, way? Even worse, for non reference types (i.e: Integers) the check for nothingness makes no sense, since a primitive type can't be nothing (yes, I could set an Integer to a non meaningful value, say -1 for a positive id, but...).

View 3 Replies

Warning: 0 : Use Procedure Bodies Is Now Obsolete.Use Check Parameters Instead

Apr 2, 2012

I'm getting this warning in my Output window (which doesn't affect functionality but I don't really understand it:

Warning: 0 : Use Procedure Bodies is now obsolete.Use Check Parameters instead

I'm using MySql.Data 6.3.7.0?

View 1 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

Pass A Nullable Valuetype Into A Non Nullable Valuetype?

Sep 17, 2009

I accidently wrote some code today that was like this[code]...

I immediately noticed the issue, but I had already hit the run button. It compiled successfully, I ran it through to the section and it threw an exception.

You can't do this in C#, it gives a compile error "cannot convert from 'int?' to 'int'".

Is there an 'Option Explicit' type switch that I can turn on to ensure that this sort of error does not occur again?

View 1 Replies

C# - Search For Names In The Database That Matches Whole Parameters Or Any Part Of Parameters

May 13, 2011

I'm writing a query to select all records that has any part of parameter. I have one table called Employees. Some people have name like this: John David Clark If the parameter is

[Code]....

I should be able to get result back as long as there's a match in the parameters. If I use Function Contains (q.FirstName & " " & q.LastName).Contains(employeeName), I will not get any result back if employeeName is "John Clark" Function Contains looks only for next words from left to right. It doesn't match a single word at a time. So that's why I used this in the Linq to SQL:

[Code]....

View 2 Replies

Error [07002] The # Binded Parameters < The # Of Parameters Makers

Aug 30, 2010

I am getting error [07002] the # binded parameters < the # of parameters makers, i checked both parameters were perfect even though i am getting this error here is my code

[Code]...

View 1 Replies

C# - Difference With Parameters.Add And Parameters.AddWithValue?

Feb 6, 2012

Basically Commands has Parameters and parameters has functions like Add, AddWithValue, and etc. In all tutorials i've seen, i usually noticed that they are using Add instead of AddWithValue.

[Code]...

since it saves my coding time. So which is better to use? Which is safe to use? Does it improves performance?

View 2 Replies

Get The GET Parameters And POST Parameters In Just One Function?

Aug 6, 2011

is there a way to get the GET parameters and POST parameters in just one function or Collection in ASP.NET? Like using $_REQUEST in PHP? I'm using VB.NET.

View 3 Replies

.net - Nullable Object Must Have A Value Vb?

Dec 5, 2011

I have a bigger code block which I have recreated in this simpler example:

[Code]...

View 1 Replies

Add Together Two Nullable Types?

Aug 27, 2010

I have: Dim nVar1 As Long?Dim nVar2 As Long?Dim nVarSum As Long?nVar1 = Nothing nVar2 = 5 nVarSum = nVar1 + nVar2 I would prefer the result to end with nVarSum being 5, instead of Nothing. I understand if you add something to an unknown value, you will end up with "somthing + unknown" or x+5 will always equal "x+5" not "5" because you are still carrying around that unknown "x". However, how can I effectively treat an unknown or Nothing as a zero for the purposes of addition in this case?(What is basically happening is that the end user is sending us a data file, this code parses that file and then sums together about 15 fields. If the user leaves those fields blank instead of assigning a zero to them, I need to treat it as if it was a zero for this one addition operation, but all the rest of the code needs to continue seeing it as a Nothing value since the user did not ACTUALLY submit zero... they submitted blank or nothing)

View 3 Replies

Can Nullable Types Be Used

Jun 27, 2012

Can Nullable Types be used in VB.NET? If so, is it possible to have a Nullable Integer that I can use with a field that accepts NULL in SQL Server?

View 4 Replies

How To Use Nullable Types

Aug 25, 2010

I'm converting an Access VBA app to VB.NET. It has dates defined as variants or objects to handle null values. I thought this would be a great chance to use the Nullable type. But I can't get it to work. Either it is inappropriate for what I am trying to use it for, or I am doing it wrong. Anyone know how to use it? Reader is a SqlDataReader.

[Code]...

I was hoping I didn't have to put a lot of If .. Null statements throughtout the code, but that is my only option unless someone has any other idea.

View 11 Replies

Nullable - What Does DataType Mean In .NET

Sep 15, 2011

I have the following line of code:

CType(IIf(CBool(product.IsDiscontinued Is Nothing Or product.IsDiscontinued = True), False, True), Boolean?)

What does the Boolean? mean at the end. I have seen it used on other data types as well.

View 3 Replies

Nullable DateTimePicker?

May 6, 2009

I have a Nullable DateTimePicker but it lacks a vital property, that is to be able to change its ForeColor, anyone who has some suggestion on how can this be done? Or perhaps a free nullable DateTimePicker out there that supports changing of backcolor and forecolor?This is C# but it should not be different with .Net, and I prefer posting it here since there is more traffic here over the C# section.

using System;
using System.Collections.Generic;
using System.ComponentModel;[code].....

View 2 Replies

Nullable Object Must Have A Value

Jan 31, 2012

Okay, none of the previous questions I have seen with this error seem to apply in this situation.tEmp is a class that contains (among other things) two nullable date fields.[code]During a routine on my form, I am attempting to see if the following conditions are true[code]I get the above error (the title of question), but when I hover over the debugger, NextReview and InsuranceEligibleDate are both Nothing (which is correct for the employee I am looking at).I am using VB2010, and the Properties in the Employee class are using the new way of declaring Properties (i.e. no set/get)

View 4 Replies

.NET: Why Doesn't This Nullable Work

Dec 15, 2010

dim str as nullable(of string) is this syntax incorrect?

View 1 Replies

C# 'AS' Equivalent For Nullable Types

Feb 15, 2011

C#'s 'as' keyword will let you do this: int? input = value as int? Here's what I would assume the vb.net equivalent would be: Dim input As Integer? = TryCast(value, Integer?) There's an intellisense error in the TryCast stating the operand must be a reference type but Integer? is a value type.

Intellisense on Nullable(Of Integer) says 'Represents an object whose underlying type is a value type that can also be assigned null like a reference type.' It seems C#'s 'as' handles this like a reference type where TryCast doesn't have this built in. In VB10 I was able to take advantage of the new CTypeDynamic function to do the casting. Conversion.CTypeDynamic Method

Dim input As Integer? = CTypeDynamic(Of Integer?)(value)

Or:

Dim input As Integer? = CTypeDynamic(Value, GetType(Integer?))

There's a cost here as CTypeDynamic examines the type at runtime.

My question is what is the elegant way to handle this without CTypeDynamic?

View 6 Replies

C# 'AS' Equivalent For Nullable Types?

Nov 15, 2011

Dim input As Integer? = TryCast(value, Integer?)There's an intellisense error in the TryCast stating the operand must be a reference type but Integer? is a value type.Intellisense on Nullable(Of Integer) says 'Represents an object whose underlying type is a value type that can also be assigned null like a reference type.'It seems C#'s 'as' handles this like a reference type where TryCast doesn't have this built in.

View 1 Replies

C# - Comparing The Nullable DateTime's?

Nov 17, 2010

I am a c#/asp.net developer and I am having to work on a VB/asp.net. I have two variables

Dim originalDate as DateTime?
Dim newDate as DateTime?

Both nullable datetimes, originalDate is a nullable date I am getting from the database and newDate time is set in code, I need to compare them, they can either both have dates, neither have dates or one have and one not.

I have a bit of code as follows:

if origEndDate = origEndDate then

When both origEndDate and origEndDate are "nothing" this statement is false (well when I run it in the watch window it comes back as nothing)!I don't understand why this is the case because I was under the impression doing an "=" compares the two values and as they are the same surely it should be true? What syntax should I be using as in C# I can do the above as so:

if (origEndDate == origEndDate) { }

and it will come back as true.

View 4 Replies

Property Keycode Is Non-nullable?

Apr 7, 2009

I am creating a setup project for my VB application. Everything seems to look fine. However when I tell it to build the solution I get the following error:Property 'keycode' is non-nullable. I have never seen this before in other setup projects and I can't find any help from MS.

View 8 Replies

Use Nullable(of T) For Property Using List<of T>?

Jan 17, 2012

In the below sample code, I have tried to use Nullable(of T) for DateTime and I want to use it same of the Dimensions property which is List(of Dimension).

CODE:

View 1 Replies

VS 2008 Nullable Object Must Have A Value?

May 20, 2009

I am getting an unusual error "Nullable object must have a value" when running the code below.

[Code].....

Interestingly the Stored proc used by the table adapter still runs and does the insert but the function returns the error.

View 8 Replies

VS 2010 Nullable DateTime?

Jun 3, 2010

For a project I need to convert a date field in my SQL Server 2008 Database into a VB.net ListOf. Most of the records in StartDate field are NULL. VB.net doesn't recognize null values for DateTime.I need the NULL values to be dismissed, as they will be returned in a ListOf for a web service that I'm creating.

Here is my syntax and a sample of the current returned values in the XML message of the ListOf:

Class Property StartDate() As System.Nullable(Of DateTime) = Nothing
asmx.vb myUserRoleAppInfo.StartDate = myPermissionUser.StartDate
XML Message (Listof)

[Code]...

View 4 Replies







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