title: How to create a table before using sqlbulkcopy
body: <p>I have a DBF file which I am trying to import and then write that to a SQL table. The issue I am running into is if I use SqlBulkCopy, it requires me to create the table in advance but that is not possible in my scenario as the dbf file changes constantly.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>public void saveDBF()
          {
  
              //define the connections to the .dbf file
              OleDbConnection oConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Path.GetDirectoryName(tbFile.Text)+";Extended Properties=dBase III");
  
              OleDbCommand command = new OleDbCommand("select * from " + Path.GetFileName(tbFile.Text), oConn);
  
              //open the connection and read in all the airport data from .dbf file into a datatable
  
              oConn.Open();
              DataTable dt = new DataTable();
  
              dt.Load(command.ExecuteReader());
  
              oConn.Close();  //close connection to the .dbf file
  
              //create a reader for the datatable
              DataTableReader reader = dt.CreateDataReader();
  
              myConnection = new SqlConnection(cString);
              myConnection.Open();   ///this is my connection to the sql server
              SqlBulkCopy sqlcpy = new SqlBulkCopy(myConnection);
  
              sqlcpy.DestinationTableName = "TestDBF";  //copy the datatable to the sql table
  
              sqlcpy.WriteToServer(dt);
  
              myConnection.Close();
  
              reader.Close();
  
          }
  </code></pre>
  
  <p>It keeps failing at <code>sqlcpy.WriteToServer(dt);</code> stating it cannot access the destination table.</p>
  
  <p>Is there an option in C# to create the table on the fly before writing to that table?</p>