How do I find out if a column exists in a VB.Net DataRow(如何确定 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 中是否存在列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何确定 VB.Net DataRow 中是否存在列


- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01