C# - Why Null == MyVar Instead Of MyVar == Null
Sep 20, 2009What the title says! I see it from times to times and I'd like to know why. Is there any difference at all?
View 6 RepliesWhat the title says! I see it from times to times and I'd like to know why. Is there any difference at all?
View 6 RepliesI have a fairly simple piece of code:
Private _PurchaseDelivery as PurchaseDelivery
Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As PurchaseDeliveryItem)
[Code]....
Which is inside a class which overrides a custom list base. The code is occassionaly throwing an unhandled exception, System.NullReferenceException, on this line when used in production:
If _PurchaseDelivery IsNot Nothing AndAlso _PurchaseDelivery.DefaultSKUBinID.HasValue Then
DeafultSKUBinID is declared as an Integer? (Nullable Int) in the PurchaseDelivery class. I cannot see what might be causing this error, why would this be returning an error?
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]....
When I put a break point to the last if clause in the sub ("If (backOrder < 0) Then", see below) it runs until the break point, if I put the break point further below, I get the following error:
Cannot insert the value NULL into column 'OrderID', table 'WHM.dbo.OrderDetails'; column does not allow nulls. INSERT fails. The statement has been terminated.
I've discovered first hand that it only happens when prodqty is bigger then qtyOnStock, thus executing the if clause.
The code:
Private Sub NCOSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NCOSubmit.Click
Dim sqlText As String = ""
[Code]....
I am trying to create a treeview in VB.net, the data has to be loaded from MSAccess 2010 database. When I try to run this program I get error : Argument Null Exception was unhandled, 'column' argument cannot be null and the program crashes. I have pasted the code as under:
Imports System.Data.OleDb
Public Class frmRating
Private Sub frmRating_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
[code].....
I have some code which gets child items for a menu via the GetChildren function which takes a list of menuData: Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu
If menuData.Children IsNot Nothing Then
menuData.Children.AddRange(GetChildren(menuData))
End If
Next
If I check if menudata.children isnot nothing, it always is nothing because the GetChildren function is yet to run (providing the child items, which do exist). If I remove this check and just have this code:
Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu
menuData.Children.AddRange(GetChildren(menuData))
Next
Then I am presented with a Object reference not set to an instance of an object error on menuData.Children.AddRange(GetChildren(menuData))
I'm having problems writing an If statement because it's asking for the value of a cookie, but it's possible that the cookie could be null which breaks the page.
Here's the code:If Request.Cookies("myCookie").Value = "1234" then'do stuff End If
I think i need an elegant way of say "If myCookie is not null and has a value of..."
[Code]...
Basically the cases are always going to be the same but it will select the case from one of 2 places depending on whether myCookie has a value. Since there may be quite a few cases is there anyway I can get away with only listing them once.?
All I want to do is check if an object is null, but no matter what I do, if it compiles, it throws a NullReferenceException just trying to check! Here's what I've done:
[Code]...
This is related to my previous question but it is a different problem.I have two classes: Server and Database.
[Code]...
The problem is in the LoadTables in the Server class. When it hits Databases.Add(db) it gives me a NullReference error (Object reference not set). I don't understand how it is getting that, all the objects are set.
We have implemented exam on a single page and store the option in view state as users selects the same. On select of next question page is loaded again. Sometime "If Session("User") = """ turns out true and user logs out.I did setup session on first time page load as
Session.Timeout = 340
Also in web config file session timeout is 2 hours.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("User") = "" Then
Response.Redirect("Default.aspx")
[code]....
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]...
I have a dataset. I'd like to check if one item in the dataset is null or zero.
If IsDBNull(ds.Tables(0).Rows(0)("TotalCostPerUnit")) or CInt(ds.Tables(0).Rows(0)("TotalCostPerUnit") = 0 Then
Exit Sub
end if
Dim Conn As ADODB.Connection
Dim Null As String
Dim NullRecordset As ADODB.Recordset
[code]....
Im trying to check my database for a null value. If the database is null, then I want it to start the timer, otherwise I want it to skip over some stuff and automatically load the main form.
I am trying to check to see if a DataSet is null or not. If it is I would like to show a MessageBox. For some reason it is not recognizing null returns and skipping the message box and going right to the Else commands. [code]....
View 3 Repliesim using a quesry which returs the max value from a table the issue is the line cmd.ExecuteScalar() may return a value null if there are no records , is there any eway to chk if value returned is null or not?
View 2 Repliesi am trying to find the loctaion of an item in an array but ecah time i run the for each next loop i get a null error. code follows:
[Code]...
I read stuff from a SQL DB (database) using a data set. Some of the columns in the DB may contain NULL. I want to go through the table in the dataset and print, or use in some other way, the data. But when I try to use a certain data that corresponds to a NULL in the DB my program crashes.How can I detect - in the dataset - that it has no value and that I shouldn't try to use it?
Private Sub Get�rendenLista(ByVal e As System.EventArgs)
'----------------------------------------------------------------------
' This function fetches a list of �rende from the table �rende
'----------------------------------------------------------------------
Dim cno As New SqlConnection
[code]....
until i put in On Error Resume Next i was getting runtime error 94 in vaild use of null
i would like to have something like case null: Result = " Unknown"
Function GetPingStatus(ByVal StatusCode As Long)
On Error Resume Next
[code].....
I have a problem with verifying db null value. Actually I don't know the syntax.
Here is the code.
If Not IsDBNull(Me.DeliveryReviewDataSet.Delivery(Me.CustomerIDListBox.SelectedIndex).Signature) Then
"Signature" is the image field (binary data).
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If MyBase.Dispose(disposing) <> DBNull.Value Then
Dispose() = DBNull.Value
[Code]....
I am getting error
1) Expression does not produce a value.
2)Expression is a value and therefore cannot be the target of an assignment.
I am using webclient to get and send various information through my vb.net application.All of the code works fine, except that whenever the webclient is used, it seems to lock-up the application (as if its going to crash) but then recovers after it has recieved/send the required data.I have googled around, and apparently i need to set the proxy to null (which is fine because i dont use a proxy anyway) but i dont know how do do this.Could anyone tell me how to set the proxy to null please?
View 2 RepliesI'm making a data application and using the data adapters, I created a query in the designer:
EmpActivities_TableAdapter.InsertQuery(IdTextBox.Text, ActivityComboBox.Text, DescriptionTextBox.Text, Cdate(adddate.text))
The question is how can I set the adddate to null or nothing and save it? I'm using SQL server for the data.
I keep getting the "Object reference not set to an instance of an object." error and it tells me to check if the pp(f, 0) object is null .... which I know it is not.[code]...
View 3 RepliesI am getting an error when I write a value to the database. it tells me "Key cannot be null. Parameter name: key". However the key is an auto-increment value and i'm not even writing to that field. I have verified that there is a value being sent to the SQL. I also created a seperate program that writes the same SQL statement to the db and it writes just fine. I also have other places within the same program that write to the database without any problems.[code]
View 17 RepliesI have two combobox on which will display company and department names. There is a"SelectedIndexChanged" event for company combobox. I don not want that is triggered when value of combobox are empty or null. I tried CompanyCombobox.seletedValue is not null and other ways, but they were not working. How do I detect there is empty or null value on combobox?
View 3 RepliesWhy my debugger throws a NullReference Exception when clearly the value is not null.
View 2 RepliesI have a function that gets a string passed to it.When testing the function, I'm getting a null reference exception on the string parameter that gets passed to it, even though the string is not null, I don't understand why I'm getting this error.I used a dummy value to verify both the string parameter in the SelectSingleNode function and the newValue string parameter being passed to my function and they both contain values, so I don't understand why it's throwing a null reference exception. Just for clarity, the purpose of the function is to write values back to the nodes of an XML file.[code]
View 3 RepliesI have a function that gets a string passed to it. When testing the function, I'm getting a null reference exception on the string parameter that gets passed to it, even though the string is not null, I don't understand why I'm getting this error. I have a screen shot belowI used a dummy value to verify both the string parameter in the SelectSingleNode function and the newValue string parameter being passed to my function and they both contain values, so I don't understand why it's throwing a null reference exception. Just for clarity, the purpose of the function is to write values back to the nodes of an XML file.UPDATE
Private Sub setValue(ByVal nodeToMod As String, ByVal newValue As String)
''Test writing to xml config file
Dim dummy As String = "Config/" & nodeToMod
[code].....
What do I have to set the path to? I've been told to set it to nothing. I also understand if this isn't enough information for everyone to work with.[code]...
View 1 RepliesThis seems like a pedestrian problem, but I just can't seem to find a solution. My problem is that I can't seem to find a way to search my datasourcefor a null value. Here's a simplified version of the problem: suppose we have a form with 3 textboxes and we wish to find a record on our datasource. if fields 1 and 2 have a value and field 3 is null, then how can I make a query using .net that searches for the values of the first 2 fields and a null value for the 3rd field? For example, suppose field 1 has a value of "ABC" and field 2 has a value of "DEF" and field 3 has a null value Now, how can I construct a query that searches "ABC" for field 1, "DEF" for field 2, and null for field 3?I'm using sqlce and below are some examples of what I've tried so far:
Dim Fld1 As New SqlServerCe.SqlCeParameter, Fld2 As New SqlServerCe.SqlCeParameter, Fld3 As New SqlServerCe.SqlCeParameter
Fld1.SqlDbType = SqlDbType.NVarChar:Fld2.SqlDbType = SqlDbType.NVarChar:Fld3.SqlDbType =
[code].....