Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out if a column exists in a VB.Net DataRow

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.

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?

like image 957
Bryan Anderson Avatar asked Oct 07 '08 14:10

Bryan Anderson


People also ask

How do I check if a DataRow column exists?

You can use the DataColumnCollection of Your datatable to check if the column is in the collection.

How do I find my DataRow column name?

You can get the column names from DataRow by using (datarow). Table. Columns and this will return “DataColumnCollection”.

What is DataRow in VB net?

By: Steven Holzner. DataRow objects represent rows in a DataTable object. You use DataRow objects to get access to, insert, delete, and update the records in a table.

What is a DataRow?

A DataRow represent a row of data in data table. You add data to the data table using DataRow object. A DataRowCollection object represents a collection of data rows of a data table.


2 Answers

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 
like image 129
John Chuckran Avatar answered Oct 02 '22 02:10

John Chuckran


You can use DataSet.Tables(0).Columns.Contains(name) to check whether the DataTable contains a column with a particular name.

like image 34
Phillip Wells Avatar answered Oct 02 '22 02:10

Phillip Wells