处理“列不属于表".例外 [英] Handling "Column does not belong to table" Exception
问题描述
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>")
-------------------------------------------------- ----------------------------
我正在使用上面的代码来制作一个xml文件.
我正在从名为"master"的xml文件中读取数据.
在主文件中,缺少一些标签,例如<电子邮件>标签,因此当我阅读电子邮件标签时,它给我列不属于表"异常.
我可以使用try-catch块来处理此异常,但是我想知道是否可以通过if-else语句来处理该异常,例如"isDBNull"或"is No Nothing".
请告诉我是否有人知道...
我将非常感谢他/她.
------------------------------------------------------------------------------
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.
推荐答案
您可以像这样检查它
You can check it like that
if(dt.Columns.Contains("COLUMNNAME"))
return dt.Rows(0)("COLUMNNAME")
else
return string.Empty
这篇关于处理“列不属于表".例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!