title: Check if column exists in DataTable
body: <p>In order to check if a column exists in a table in my Microsoft Access database, I wrote this code using VB.net:</p>
  
  <pre><code>       Dim conCreate As New OleDb.OleDbConnection(strCnn)
         conCreate.Open()
         Dim dbSchemaData As DataTable = conCreate.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, "Data", "TABLE"})
         conCreate.Close()
  
         Dim row As DataRow
         row = dbSchemaData.NewRow()
  
                  For arrItem As Integer = 0 To arrLine.Length - 1
  
                      If arrLine(arrItem) = "Image Filename with Full Path" And row.Table.Columns.Contains("Tif") = False Then
  
                          Dim cmdCol As New OleDb.OleDbCommand("ALTER TABLE [Data] ADD COLUMN [Tif] VARCHAR(255)", conCreate)
                          conCreate.Open()
                          cmdCol.ExecuteNonQuery()
                          conCreate.Close()
  
                      ElseIf arrLine(arrItem) = "Image side" And row.Table.Columns.Contains("Voorkant") = False Then
  
                          Dim cmdCol As New OleDb.OleDbCommand("ALTER TABLE [Data] ADD COLUMN [Voorkant] BIT", conCreate)
                          conCreate.Open()
                          cmdCol.ExecuteNonQuery()
                          conCreate.Close()
  
                      ElseIf arrLine(arrItem) = "Image size (bytes)" And row.Table.Columns.Contains("Bestandsgrootte") = False Then
  
                          Dim cmdCol As New OleDb.OleDbCommand("ALTER TABLE [Data] ADD COLUMN [Bestandsgrootte] NUMERIC", conCreate)
                          conCreate.Open()
                          cmdCol.ExecuteNonQuery()
                          conCreate.Close()
  
                      ElseIf row.Table.Columns.Contains(arrLine(arrItem)) = False Then
  
                          Dim cmdCol As New OleDb.OleDbCommand("ALTER TABLE [Data] ADD COLUMN [" &amp; arrLine(arrItem) &amp; "] VARCHAR(255)", conCreate)
                          conCreate.Open()
                          cmdCol.ExecuteNonQuery()
                          conCreate.Close()
  
                      End If
  
                  Next    
  </code></pre>
  
  <p>But running this while for example the first column (named Tif) already exists, it still tries to add it and proceeds to give the exception 'System.Data.OleDb.OleDbException' in System.Data.dll ("Field 'Tif' already exists in table 'Data'."), stopping the loop.</p>
  
  <p>Any help would be appreciated!</p>