Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
XML
If System.IO.File.Exists(strPathName & "_Master.xml") Then
            dsMaster.ReadXml(strPathName & "_Master.xml")
        Else
            MessageBox.Show("Master does not exist")

        End If
            Dim rowMaster() As DataRow = dsMaster.Tables(0).Select("FinYearID=" & GlobalClass.finYearId & " And MemType='" & GlobalClass.MemType & "' And MemberID='" & rowTran("MemberID") & "'")

Dim strBuilder As New StringBuilder
            strBuilder.AppendLine("<?xml version='1.0' encoding='utf-8'?>")
            'declare the start root.
            strBuilder.AppendLine("<ReportInfo>")
            strBuilder.Append("<Info>")

 strBuilder.Append("<Email>")
            Try
                strBuilder.Append(rowMaster(0)("Email") & "") ' to test if there is any "Email" column in master table or not ?
            Catch ex As Exception
                strBuilder.Append("")
            End Try
            strBuilder.Append("</Email>")

  strBuilder.Append("</Info>")
            'declare the end root.
            strBuilder.AppendLine("</ReportInfo>")




------------------------------------------------------------------------------
I am using the above code to make an xml file.
I am reading the data from an xml file named "master".
In master file there is some tag missing e.g. <email> tag, so when I read email tag it gives me "Column does not belong to table" Exception.

I can handle this exception with try-catch block, but I want to know if there is any way to handle it with if-else statement, like 'isDBNull' or 'is Not Nothing'.

Please tell me if anyone knows...
I will be very thankful to him/her.
Posted
Updated 1-Jun-20 21:23pm
v2
Comments
Dalek Dave 11-May-11 3:29am    
Edited for Grammar and Readability.

1 solution

You can check it like that
if(dt.Columns.Contains("COLUMNNAME"))
   return dt.Rows(0)("COLUMNNAME") 
else
   return string.Empty
 
Share this answer
 
v3
Comments
Dalek Dave 11-May-11 3:29am    
Nice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900