Datatable – Does Column Exist?

Need some help to create a simple logic statement to determine if a datatable contains a column with a specific name.  If the column does not exist, then I want to create it.  If the column does exist, skip the “Add” routine.  I think this can be done very easily, but I don’t know the correct syntax to use for the "IF" statement.   Thanks for the help!
If  (Column “Address” does not exist then Add it)
{
dt.Columns.Add("Address", typeof(string));
}

Open in new window

dev775Asked:
Who is Participating?
 
robastaConnect With a Mentor Commented:
if(!dt.Columns.Contains("Address")0
{
 dt.Columns.Add("address", typeof(string));
}
0
 
robastaCommented:
that '0' should be a ')'
0
 
dev775Author Commented:
Works perfectly - thanks!
0
All Courses

From novice to tech pro — start learning today.