June 5, 2014 by Nitesh

How To Check If a Column Exists in DataRow

Friends,

This is a very small post to explain how can you check whether a column exists in a DataRow. This is a very handy tip when you are working with a set of data and you’re not sure everytime the query will return a specific column. Let us assume we have a DataRow named “row” and we want to check whether a column named “Active” exists in this DataRow or not.

To check for the column existence, you can use the below line of code –

   if(row.Table.Columns.Contains("Active"))
   {
      Console.WriteLine("Column Exists");
   }
   else
   {
      Console.WriteLine("Column Does Not Exists");
   }

Keep learning and sharing! Cheers!

#.Net#ASP.Net#C##Utilities#Winforms

Support us!

If you like this site please help and make click on any of these buttons!

Powered by WordPress Popup