Extension On Nullable(Of T) Object, Gives Type Error?

Oct 29, 2010

The code I want to work:

<Extension()>
Public Function NValue(Of T)(ByVal value As Nullable(Of T), ByVal DefaultValue As T) As T
Return If(value.HasValue, value.Value, DefaultValue)

[code].....

View 2 Replies


ADVERTISEMENT

Error In Assigning Object Of Nullable Type?

Jul 9, 2010

I have a structure that contains another structure. The inner structure is nullable. Now wht I do is something like the following. I create a new instance of the inner structure, set the member variables and assign the whole structure to the inner structure of the parent. But it is giving an error. The assignment is not successful. If I try to peek into the structure in the watch window, it says "property evaluation failed" for the HasValue and Value properties.

Dim testData As List(Of TestData) = Nothing
Dim testData_List1 As New TestData
With testData_List1.commonTestParam

[Code].....

View 1 Replies

Cast Value Type To Nullable Enumeration Type In Generic Object If All Types Are Unknown At Write-time?

Dec 14, 2011

I have a generic Class I'm using to hold information loaded from a database.I have a method which takes a DataRow as an argument, uses the object's known column name and extracts the data from the DataRow, such that:Dim loadData As T = CType(myDataRow("myColumnName"), T))works as my default assignment in most cases.Unfortunately, due to some horrifying design constraints, some of my columns may be null, and may also be taken from enumerations.This means that when <T> is Nullable(Of SomeEnumeration) the above code does not work because I can't cast 0 directly to SomeEnumeration.Zero.Is there some way to check whether <T> is Nullable(Of [Enum])? Or some way to write a method which allows Integers to be cast to Nullable(Of [Enum])?I feel like I'm forgetting something that would allow me to write one of the other of these, but my weak google-fu is turning up nothing.

EDIT: Okay, thanks to dasblinkenlight's answer below, I can detect when this circumstance is occurring, but what I need to do now is to take a type <T> which I know is Nullable(Of SomeClass), get a type reference to SomeClass and then create a new object of type Nullable(Of SomeClass) and assign that to LoadData.My problem was that I had a lot of difficulty in finding any function which would accept baseType as an actual Type.Parse accepted baseType as a parameter, I knew baseType was an [Enum] type because of dasblinkenlight's code, so I was, in this instance, able to code a solution. It's a solution which is very specific to my problem (i.e., T is Nullable(of SomeEnumeration)), but it's a solution nonetheless.

View 2 Replies

Cast An Object To A Nullable Of Type Struct?

May 20, 2009

In the code base I'm working in there have a method that has the signature

Public Sub SetDropDownValue(Of T As Structure)(ByVal target As ListControl, ByVal value As Nullable(Of T))

The method I am writing is passed a parameter of type object.

How can I cast the object into something that can be passed into the SetDropDownValue method?

View 2 Replies

Error : Unable To Cast Object Of Type 'ClassA' To Type 'ClassB'

May 24, 2011

I can't cast my objects. I get: "Unable to cast object of type 'ClassA' to type 'ClassB'".

The service Class:

Public Class svc_Insp
Implements Isvc_Insp
Public Function Test(ByVal pm_income As ClassC) As String Implements Isvc_Insp.Test

[code]....

View 1 Replies

Error - Unable To Cast Object Of Type 'AbstractListlistIterator' To Type 'System.Collections.IEnumerator

Dec 22, 2010

I have a series of API calls that are returning J# data types. I have been able to convert most of the data types (Integer, Boolean, Double, Float, etc) just fine.What I need to do now is convert a java.Util.Collection to a VB .NET collection (ArrayList)

Here is my attempt:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection
Dim dotNetCol As Collection

[code]....

I keep getting a runtime error "Unable to cast object of type 'AbstractListlistIterator' to type 'System.Collections.IEnumerator.

View 1 Replies

VS 2008 : Error - Unable To Cast Object Of Type 'ObjectCollection' To Type 'System.Array'

Feb 24, 2012

I am using a background worker and am attempting to use the following code. However I keep getting this error on i "Unable to cast object of type 'ObjectCollection' to type 'System.Array'."

Private Sub btnVerify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerify.Click
myArray = listProxies.Items()
BackgroundWorker1.RunWorkerAsync()
End Sub

[code]....

View 2 Replies

The Null Value Cannot Be Assigned To A Member With Type System.Decimal Which Is A Non-nullable Value Type?

Sep 15, 2010

I have a Job Register Table and that table doesn't have any records.

This is my LINQ code:
Dim QRecordCount = (From LC In CntxtJobDetails.JobRegistrations _
Where LC.JobCode <> 0 _

[code].....

View 1 Replies

The Null Value Cannot Be Assigned To A Member With Type System.Int32 Which Is A Non-nullable Value Type?

Aug 18, 2010

When i execute this linq to sql command its given an error "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type." 0 Records in my Commotidy Table

I want generate manual number and get the last CommodityCode.My Code as follow,

Dim QRecordCount = From RC In cntxtCommodity.CommodityMasters _
Where RC.CommodityCode <> 0 _
Select RC.CommodityCode[code].....

View 1 Replies

Error : Unable To Cast Object Of Type 'Object' To 'CTest'

Feb 22, 2012

I have

Public stack() As CTest

I want

Public stack() As Object

The latter is giving the error "Unable to cast object of type 'Object' to 'CTest'." when used:

Dim thestack As CTest() = testdatabase.getStack
Where testdatabase.getStack simply returns stack();
Public Function getStack() As Object()
Return stack
End Function

This fixes it, but it's not ideal (for me personally):

Dim thestack As Object() = testdatabase.getStack

So if I could keep the variable as-is (Public stack() As Object) and then do something along the lines of class.stack() = CTest I should be able to do Dim thestack As CTest() = testdatabase.getStack because the object array will programmatically have changed from Object to CTest.

View 1 Replies

Error : Unable To Cast The COM Object Of Type 'System._ComObject' To Interface Type 'Microsoft.Office.Interop.Word.CustomProperties'

May 10, 2009

I have been trying to use vb2008 to automatically update CustomDocumentProperties fields that I have set up within a pro-forma document. I can load the Word application and word document without problems.I want to update the CustomDocumentProperties fields with data read from a dB. To do this I am assuming that I need to iterate through the CustomDocumentProperties fields within the word document and when one is "found" that matches the data I wish to merge then assign the dB value to the field.The problem is that I am getting an exception error when I try to reference the document customdocumentproperties

"Error : Unable to cast the COM object of type 'System._ComObject' to interface type 'Microsoft.Office.Interop.Word.CustomProperties'. ...... "

my code looks like;

Dim WordApp As Word._Application
Dim odoc As Word._Document
Dim BContinue As Boolean = True

[code].....

View 2 Replies

Error : Unable To Cast Object Of Type 'System.EventArgs' To Type 'System.Windows.Forms.KeyPressEventArgs'

May 16, 2011

[URL]The issue is as soon as I change the value of the text boxes it gives me an error and forces me to close the project.

The error is:Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'.

However I'm supposed to clear the number of gallons used and the total charged when a change is made to the contents of the 2 text boxes on the form.

View 3 Replies

Error Unable To Cast Object Of Type 'System.Data.SqlTypes.SqlDecimal' To Type 'System.IConvertible'

Jun 6, 2011

I have an InvalidCastException Error in my program. The program is that i try to insert an employee record into a database table after getting the details from a form. I've used Money data type is SQL Server for salary and SqlTypes.SqlDecimal data type in employee template class. i've used a stored procedure to pass the values and i add the basic value by passing a parameter by the method

Dim prm8 As SqlParameter = com.Parameters.Add("@basic", SqlDbType.Money)
prm8.Direction = ParameterDirection.Input
prm8.Value = emp.Bsc

I've used the money datatype itself even in the stored procedure variable.I get the following error.

failed to convert parameter value from sql decimal to decimal
Even if i use
prm8.Value = Convert.ToDecimal(emp.Bsc)

I get an error Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible'.

View 3 Replies

Ado.net Error (Unable To Cast Object Of Type 'System.String' To Type 'System.Data.IDataReader'.)?

Jan 29, 2012

I am getting this error when I am tring to load string type to data table)

Using connection As New SqlConnection("connectionstring;")
connection.Open()
Using Command As New SqlCommand("SELECT ClientId,forename,surname from t_clientdetails

[code].....

View 1 Replies

ASP.Net Error - Unable To Cast Object Of Type 'System.String' To Type 'System.Data.DataTable'

Oct 4, 2009

I get the below error Unable to cast object of type 'System.String' to type 'System.Data.DataTable'.This is the code I'm using

Dim str As String = String.Empty
If (Session("Brief") IsNot Nothing) Then
Dim dt As DataTable = Session("Brief")
If (dt.Rows.Count > 0) Then

[code]....

View 3 Replies

Can't Copy Paste Cut Code - Gives Error "Unable To Cast Object Of Type 'Public_Information_System_Remake.PIS' To Type System.Windows.Forms.TextBox"

Mar 31, 2011

same errors or something related to System.windows.forms. Unable to cast object of type 'Public_Information_System_Remake.PIS' to type 'System.Windows.Forms.TextBox'.

[Code]...

View 5 Replies

Error: Option Strict On Disallows Operands Of Type Object For Operator '='. Use The 'Is' Operator To Test For Object Identity

Jan 27, 2010

I am tightening up my coding with the Option Strict set to ON. It has now produced alot of errors. An example of this is:

If AllocatedDGV.Rows(i).Cells("RoomNumber").Value = RoomsAvailableDGV.Rows(j).Cells("RoomName").Value Then

It gives me the following error: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

View 6 Replies

Error Object Must Be Of Type Decimal?

Apr 20, 2010

When I click on a header (Price) to sort the rows by that column, I get an error Object must be of type decimal.

I'm thinking that I'm encountering a new row without any values that's why this error is being generated.

I'm not sure how to intercept this error or fix it for that matter....

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

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

Error : Unable To Cast COM Object Of Type

Jul 22, 2011

I have do the coding to export the data from DataGridView to Excel. But If am running the code am getting the below error.

[Code]...

View 4 Replies

Getting Error Unable To Cast Object Of Type?

Aug 15, 2011

I seem to have broken something I get this error Unable to cast object of type System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'.

my code:
Private Sub ListControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListControl.SelectedIndexChanged

[code].....

View 1 Replies

Unable To Cast Object Of Type Error

Mar 28, 2011

i write this code to work with some radio button and calculate Score for a questionare : Dim SScore AsByte = 0 Dim BTNN AsByte = 0 Dim BTNNS AsString = "" ForEach rBTN AsRadioButtonInMe.Controls If Mid(rBTN.Name, 1, 5) = "RBS01"Then If rBTN.Checked Then SScore = SScore + CType(Mid(rBTN.Name, 7, 1), Byte) EndIf EndIf Next I get this error on line 4 : Unable to cast object of type 'System.Windows.Forms.Button' to type 'System.Windows.Forms.RadioButton'. i dont know what is it and how can handle it.

View 5 Replies

Compare Two Variables Of Type Nullable?

Jun 9, 2011

I'm trying to compare two variables of type nullable(of boolean) in VB.NET 2010. One of the variables has a value False and the other is Nothing. Now I was expecting the following expression to evaluate to true, but this is not the case:

Dim var1 as nullable(of boolean) = False
Dim var2 as nullable(of boolean)
var2 = Nothing

[Code].....

Why don't I see my MsgBox? How should I compare two nullables (of boolean)?

View 4 Replies

Nullable(Of ) : Type Of Parameter For <Attribute>?

Mar 23, 2011

I'm trying to use the type Boolean for some parameter.

<AttributeUsage(AttributeTargets.Method, Inherited:=True, AllowMultiple:=False)>
Public Class MyAttribute
Inherits Attribute

[code].....

View 14 Replies

Populating A Nullable Type From A DataRow?

Nov 11, 2010

I want to get a value from an item in a DataRow and I would like to store the result in a Nullable Date field.

I see (in VB) that there appears shared "Field" function on the object System.Data.DataRowExtensions. Here's from the Object Browser:

Public Shared Function Field(Of T)(ByVal row As System.Data.DataRow, ByVal column As System.Data.DataColumn, ByVal version As System.Data.DataRowVersion) As T
Member of System.Data.DataRowExtensions

[Code].....

Does somebody have a better way to move values to and from a datarow into Nullable types?

..OR is there a built-in handy function to do this so I don't have to define my own?

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

.net - Determine If A Generic Parameter Is A Nullable Type?

Mar 3, 2011

I have the following VB.NET function, for example:

Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TData
End Sub

How do I, in a function, determine if TData is a NULLable Type?

View 3 Replies

Determine If A Generic Param Is A Nullable Type?

Dec 14, 2006

I have the following VB.NET function, for example:Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TDataEnd Sub

View 5 Replies

Implement Nullable Parameter Of Type String?

Jan 18, 2010

how to implement Nullable Parameter of type string in vb.net

Function:

sub savedetail(byval name as string, byval age as integer)
if name isnot nothing then
some work
end if

[code]....

View 1 Replies







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