如何查看VB.Net DataRow中是否存在列 [英] How do I find out if a column exists in a VB.Net DataRow
问题描述
我正在将XML文件读入DataSet,需要从DataSet中获取数据。由于它是用户可编辑的配置文件,所以字段可能也可能不在那里。为了处理丢失的字段,我想确保DataRow中的每一列都存在,而不是DBNull。
I am reading an XML file into a DataSet and need to get the data out of the DataSet. Since it is a user-editable config file the fields may or may not be there. To handle missing fields well I'd like to make sure each column in the DataRow exists and is not DBNull.
我已经检查了DBNull,但是我不知道如何确保列不存在异常或使用循环遍历所有列名的函数。这样做最好的方法是什么?
I already check for DBNull but I don't know how to make sure the column exists without having it throw an exception or using a function that loops over all the column names. What is the best method to do this?
推荐答案
DataRow的方式很好,它们的底层表与之链接。使用基础表,您可以验证一个特定的行在其中有一个特定的列。
DataRow's are nice in the way that they have their underlying table linked to them. With the underlying table you can verify that a specific row has a specific column in it.
If DataRow.Table.Columns.Contains("column") Then
MsgBox("YAY")
End If
这篇关于如何查看VB.Net DataRow中是否存在列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!