The code below works fine as long as there are values within an XML node (For example the <CPU>Intel</CPU> node below) but it throws an Exception error when the node value is blank/null whatever as in the example node <Monitor> </Monitor>.t's ok if the node value is blank, I just want to check for it and not throw an exception error.This question uses the following XML snippet below: Note: The tag <Monitor></Monitor> has no value in it.
I have the following code that checks if the value in a cell contains a nummeric value.
Private Sub dgvOrderRegel_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvOrderRegel.CellValidating Select Case e.ColumnIndex Case 4 'Aantal If Not IsNumeric(e.FormattedValue) Then
I'm using FileHelper to generate object's property. Here is an example of one property:
<FieldOptional(), _ FieldTrim(TrimMode.Both)> _ <FieldNullValue(GetType(String), " ")> _ Public StoreNo As String
As you can see the StoreNo will either have a value or " ", one of the business policy is to check if the StoreNo is empty or nothing if the object's StoreNo is empty or null then the record will not create.
I though about creating an HasValue Function in the class to check the StoreNo and other properties in the object but I feel like it is a hack.
Public Function HasValue() As Boolean Dim _HasValue As Boolean = True If StringHelper.IsNullOrBlank(Me.StoreNo) Then
[Code]....
I don't think this approach is an ideal solution. what if the StoreNo is remove or change to something else. What's the best approach to check object's property?
This must've have been asked before but I couldn't locate it. In a mixed code project (VB and C#) we were debugging some old Visual Basic code where a statement as follows could be found:
If Request.Params("xxx") <> "" Then 'do something
I considered this a bug as Request.Params could be null, in which case the statement would've become false which wasn't the idea. So I thought. I just found out, -- probably for the tenth time and I will keep forgetting -- that the following two statements are not equal, while Nothing in VB should be equal to null in C# (thought I):
if(String.Empty == null) // always false If String.Empty = Nothing Then ' always true
Should I dismiss this as a typical Microsoft backward compatibility effort, or should I consider this a huge error in the VB.NET compiler? Does anybody know the Microsoftean opinion on this oddity?
i have a date control on form (vb.net) and by default its value is current date. i want to make its value to null or empty so that no date is shown and user choose from the drop down date calendar.
I have several different applicaitons that were originally created with Visual Studio 2005 / .net framework 2.0 / Windows XP that got common settings from an App.Config file on a network share. Each of these applications has an app.config file with the following:
I am now trying to make these applications work in a Windows 7 / .net framework 3.5 / Visual Studio 2008 environment and can't seem to access the settings in \fileServerconfigcommon.app.config in the same way the old environment allowed. I'm wondering if there is some new way to do this. I need to have the applications read their settings from a common file on the network share (having the applications take their own copy is not accpetable).
I'm deserializing some XML from an old application into an object in my current application. The old XML often has empty elements (<SomeElement />) which are currently deserialized as empty strings (""). I agree that this is the most appropriate behaviour, but it is a minor irritant; I'd rather they were deserialized as Nothing or ideally ignored - the effect would be the same. Is there a means of ignoring these elements? Or can I have them deserialized as Nothing?
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.
I constantly find myself having to do code similar to the following.[code]Is there anyway to check for both on a single line? When i'm checking a condition for a great number of answers, I sometimes end up with conditionals 6-sets deep. If i check for null first, an error still pops up, even though VB shouldn't check since the first condition failed. i.e.[code]
How can I change the following code to write to the database null instead of empty strings?
Public Sub SetChangeRequest(ByVal referenceLeaseID As Integer, _ ByVal referenceCustomerID As Integer, _ Optional ByVal custUnitNum As Object = Nothing, _
I have a form and stored procedure that inserts the data from the form. It works fine except that if a field isn't filled in it doesn't insert a NULL into SQL it inserts "".
I've tried a few different ways but none seem to insert NULL, the one below still inserts "", can anyone point me in the right direction?
Here is the required part of the code, if you require more just let me know.
Dim rdr As SqlDataReader Dim cmdInsert As SqlCommand = New SqlCommand() cmdInsert.CommandText = "spPersonalDetailsInsert"
[Code].....
So if I enter nothing into address1 field it should write NULL to screen but it always writes NOT NULL. What does an empty form field equal? in classic ASP it was always "".
I have a couple of textfields in a Windows form. One of these textfields is allowed to be NULL. When I enter a value for every field, it is all inserted, no problem. When I leave the field (txtGewicht) blank, I can't seem to be able to insert NULL in Access Database.
If Double.TryParse(txtGewicht.Text, 0) Then klant.Gewicht = Double.Parse(txtGewicht.Text) Else
[Code]....
This is what I get:
"Cannot set column 'Gewicht' to NULL, please use DBNull instead"
So I changed 'Nothing' to DBNull.value, but it then tells me that System.DBNull cannot be converted to type Double.
I have a large one dimensional array that is called ArrayHold which is populated at runtime. I run a loop to scan through the array to find out which elements need to be removed based on a few parameters. This all works great, now I am left with two arrays. The original one and a new one which contains the locations of the elements to be removed.
Original Array: ("A")("B")("C")("D")("E")("F")("G")("H")
Second Array with index/count of elements that needs to be removed: ("0")("3")("5")("7")
End result should be preferably not in a new array but a "ReDim" of the original array:("B")("C")("E")("G")
What would be the simplest way to achieve this? I could run a loop to make all the elements that need to be removed "0" or ""? Would there be an easy way of resizing and array by dropping/removing all the white space or empty elements?
While writing an app that uses a couple settings, they occasionally get re-set to empty. I haven't seen any pattern to this, but I do have a vague memory that there are certain circumstances that will reset the settings in a project under development. What are the circumstances that cause the settings to be reset?
I need to sort a DataTable or DataGridView by a column that is a string value, but with null/empty values at the BOTTOM when sorting ASCENDING. The DataTable is NOT populated by a SQL statement, so no order by. If I do
Now I can't use cmbReplcmnt.Text because what I actually need is the value of that SelectedItem
So problem is, if the user leaves the combobox as blank, it throws a null exception.I decided to use the IIf function then:classEquipmentItem.ReplacementTo = IIf(IsNothing(cmbReplcmnt.SelectedItem.ToString), classEquipmentItem.ReplacementTo = "", cmbReplcmnt.SelectedItem.ToString)
Unfortunately I still get the error I tried using a Try-Catch for it and it worked, but I don't want to rely on the Try-Catch, so I was wondering is there a another way to work this through?
I need to sort a DataTable or DataGridView by a column that is a string value, but with null/empty values at the BOTTOM when sorting ASCENDING.The DataTable is NOT populated by a SQL statement, so no order by.If I doDataGridView1.Sort(New RowComparer(System.ComponentModel.ListSortDirection.Ascending))then it throws an exception, saying that the DataGridView is DataBound, which is correct, but doesn't help me, and I want to keep it databound.
i have a dataset that takes results from a select to a sql database. the select returns rows and sometimes returns no rows. how can i check if the dataset has no rows from the select? [Code]
I need to check if a .txt file is empty, if it's not, the code will read the file and process the information.I know how to read .txt file. Is there a way to check if the .txt file is empty? not an empty line just completely empty?
On a button click I need to test whether or not an array has been filled, if it has the user gets linked to a new form otherwise they receive a message box telling them to first assign values to the array.
I've tried 'If MyArray Is Nothing Then....' and 'If MyArray.Length < 1 Then...' but neither seemed to have worked.