如何确定 VB.Net DataRow 中是否存在列 [英] How do I find out if a column exists in a VB.Net DataRow

查看:19
本文介绍了如何确定 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆