Data field value is null do not show end element

db , xml United States
  • 12 years ago
    Hello,

    I'm using XMLWriter to create a XML file from a database table.

    I use WriteElementString to create elements. I'm having

    1. When a data field is NULL
    I dont want to show the end elemt in XML FILE
    2. When a data field is a date/timestamp field, I get an error.

    Any help will be appreciated. Thanks.

     Below is my code

     While dr.Read()
                    xw.WriteStartElement("Form")
                    For i As Integer = 1 To 1
                        xw.WriteAttributeString(dr.GetName(i), IIf(IsDBNull(dr.GetValue(i)), String.Empty, dr.GetValue(i)))
                    Next
                    For i As Integer = 0 To 0

                        xw.WriteElementString(dr.GetName(i), IIf(IsDBNull(dr.GetValue(i)), String.Empty, dr.GetValue(i)))
                    Next
                    'xw.WriteEndElement()
                    xw.WriteStartElement("Name")
                    For i As Integer = 2 To 9
                        xw.WriteElementString(dr.GetName(i), IIf(IsDBNull(dr.GetValue(i)), String.Empty, dr.GetValue(i)))
                    Next
                    xw.WriteEndElement()
                    xw.WriteStartElement("Form")
    end while

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard