How To Deserialize Empty Element As Null

Mar 7, 2012

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?

View 2 Replies


ADVERTISEMENT

[2008] - Deserialize An Empty Arraylist Collection?

Mar 6, 2009

the vars outside the procedure

Dim rentalRecords As New ArrayList() ' The arraylist containing the records
Dim carRecords As New ArrayList()
Dim currentRecordIndex As Integer ' The index of the current record

[code]....

View 1 Replies

File Container - "Attempting To Deserialize An Empty Stream."?

Dec 13, 2011

I found this on MSDN and the issue never got resolved, but I figure it would give me an idea of where to start for creating a container to hold a set of files of varying file types. No compression is needed, so just something very simple.

Imports System.IO
Public Class Form1
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

[code].....

View 7 Replies

JSON.NET Deserialize - Next JSON String - Returns Always An Empty Result

Feb 21, 2011

I'm strugling the whole day with the next JSON string

{
"0":{"link":"afbeeldingenplaatje1.jpg"},
"1":{"link":"afbeeldingenplaatje2.jpg"},
"2":{"link":"afbeeldingenplaatje3.jpg"}
}

How can i deserialize this? What's wrong with the next code (vb.net)

Public Class DataString
Private m_link As String
Public Property link() As String
Get

[CODE]...

It returns always an empty result.

View 1 Replies

Get The Value Of An XML Element Using Linq Even When Empty?

May 13, 2010

Please excuse my stupidity, I tend to find the traversing XML overly complicated.

[Code]...

Once it gets to staffBio I get an error saying "Object reference not set to an instance of an object." obviously because that node does not exist. My question is how can I assign the value to a variable even when it is empty without having to do a conditional check before each assignment?

View 2 Replies

Array Element Default If Empty?

Nov 28, 2011

i noticed a problem with a program i made that occurs when an array element is called to use but is empty under a certain condtion therefor throwing an exception. i tried to define that element after the array was initialized to give it a default to use, but its not workin for me?

View 8 Replies

VS 2008 XML Write Empty Element?

Jul 26, 2009

Im trying to create an empty element in an xml file but still want to be able to close other elements without changing the empty element.What XMLTextWrite does to empty elements:
<Data>
<Feed>
<EmptyElement />
</Feed>
<Data>

When i use the text writer i cant use <writer>.StartEndElement() it starts to screw with my empty element. When im still having my program write inside feed. Here some code your you to drool over.

My example

Dim Settings As New XmlWriterSettings()
Settings.Indent = True

[code]....

View 1 Replies

Nothing Equals String.Empty, Null Does Not Equal String.Empty?

Jun 28, 2010

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?

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

Date With Empty/null Value?

Jun 23, 2009

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.

View 9 Replies

Error Pop Ups When There Is Empty / Null Value

May 7, 2010

I am getting the attached error when any cell in a row is empty. How to avoid this error and to accept the null values?

View 4 Replies

XElement.Element.value Throws Null Reference Exception

Aug 10, 2011

Goal: Load a validated xml file in to memory, traverse through the document to create objects and load object properties with values in named xml tags.Problem: How do I deal with missing tags?Amplifying information: in this example, there are three values I'm looking for; name (mandatory), location (optional), comments(optional). I found the problem in prototyping the solution. My inital test was with an xml file wtih all fields present. It works fine as long as I don't have nanespace declarations in the root element. However, if I leave them in place I get a null reference exceptoin. The same thing occurs if I leave off an optional tag. It appears that if the Element I'm trying to get a value on doesn't exist within that element, a null reference exception is thrown.

Code:

Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
Dim xelement As XElement = xelement.Load(txtXMLfileLoc.Text)
Dim ICAOxs As IEnumerable(Of XElement) = xelement.Elements()

[code]....

View 5 Replies

Check Null And Empty Both At A Time?

Jun 17, 2009

I am getting product id value some times null and empty from databasehere how i check if valule null and empty

productid = IIf(IsDBNull(TempDT.Rows(0).Item("productid")) =
True,
"", TempDT.Rows(0).Item("productid"))

[code].....

View 11 Replies

Check If XML Node Is Empty/Null/Blank?

Apr 8, 2010

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.

<PCSettings>
<SystemSettings>
<CPU>Intel</CPU>

[code].....

View 1 Replies

Check To See If Applications Settings Are Null Or Empty?

Apr 7, 2012

I have some application settings that I want to put some error checking in and the below code does not work.

If My.Settings.SmtpServer = ("") Then
MsgBox("SMTP cannot be blank!", vbExclamation, "SMTP App")
End If

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

Made Empty Or Null Field In Datagridview

Nov 15, 2009

I key-in data from textbox to datagridvie..........the date data the format datatable is:

[Code]...

View 1 Replies

Nested If Loops Checking For Null And Empty

May 27, 2010

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]

View 8 Replies

Sql - Write Database As Null Instead Of Empty Strings?

Jan 12, 2010

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, _

[CODE]...

View 6 Replies

VS 2010 Check DGV Cell For Null Or Empty Value?

Feb 29, 2012

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

[Code]...

View 4 Replies

Check Object's Property For Null Or Empty String?

Jul 28, 2009

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?

View 3 Replies

Insert NULL Into Database If Form Field Is Empty Using ASP.NET & VB?

Jan 18, 2011

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 "".

View 4 Replies

Inserting Empty String Field As Null In Access?

Jan 4, 2012

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.

View 1 Replies

Resize Array By Removing All Empty/null/0 Elements?

Jun 2, 2012

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?

View 1 Replies

C# - Sorting DataTable String Column But With Null / Empty At The Bottom

Feb 7, 2011

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

[Code]...

View 3 Replies

Combo Box Selected Item Is Null - Assign An Empty String To It Instead?

Dec 9, 2011

I have a property called ReplacementTo and I set a value to it based on the selecteditem from the combobox, like this:

classEquipmentItem.ReplacementTo = cmbReplcmnt.SelectedItem.ToString

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?

View 2 Replies

DB/Reporting :: Stored Procedure Test For Null/empty Uniqueidentifier

Sep 6, 2008

I have a stored procedure (SQL Server Express) that returns a count of records:

SELECT COUNT(AdminUserID) AS CountEm
FROM Licenses
WHERE (AdminUserID = @AdminUserID);

Table "Licenses" has a field "CompanyID" which is a uniqueidentifier.

I need to add a clause to the WHERE to exclude records from the count where "CompanyID" is null/empty.

In VB code I'd do this with "If Not (TheCompanyID.Equals(Guid.Empty)) Then"

How would I do this in a stored procedure?

View 2 Replies

Sorting DataTable String Column, But With Null/empty At The Bottom?

Mar 5, 2009

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.

View 2 Replies

VS 2005 Insertion - Leave A Single Field Containing A Null Value "empty"

Jul 26, 2009

This is my database: Here is my

[Code]...

View 31 Replies

Asp.net - Element 'system.webServer' Has Invalid Child Element 'rewrite'?

Feb 14, 2012

I have a number of rewrite rules for a lot of things that I did in IIS7, like removing trailing slashes, canonnical URLs, lowercase lettering, and such. IIS altered my web.config, and everything works fine on the website, like it should. But in the Visual Studio web.config, the opening < rewrite > statement is underlined in blue, and at the bottom of VS, it says that the element 'system.webServer' has invalid child element 'rewrite'. But this is how IIS made it. I didn't do this manually. Should I be concerned with this VS error, or should I just leave as be, since it's working how it should work? Here's an example of my web.config:

[Code]...

View 1 Replies







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