title: Encountering Error when trying to INSERT INTO an excel file
body: <p>I'm trying to figure out how to insert a row of data into an existing Excel file.   The file is simple with ONLY 3 headers,  CITY STATE and ZIP.   I've selected the 3 cells in Excel and named the range Browns.  When I run the program I get an error code.    Number of Query Values and Destination fields are not the same.</p>
  
  <p>This is what I pass into the method</p>
  
  <pre><code>Excel_IO.inSertRowTEST(filePath1.Text, "Browns");
  </code></pre>
  
  <p>Methods I've created. </p>
  
  <pre><code>public static void inSertRowTEST(string FP1, string TableName)
      {
          string sql = null;
          Excel_IO.openSheet(FP1);
          sql = "INSERT INTO  " + TableName + " VALUES ('Jack','Smith')";
          myCommand.CommandText = sql;
          myCommand.ExecuteNonQuery();
          Excel_IO.closeMyConnection();
  
  
      }
  
  public static void openSheet(string filePathMain)
      {
          // MyConnection Equals A New OleDbConnection, The Connection Defines Which Versions Of Excel Files Can Be Used, The file path, And Some Basic Excel Properties
          MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ace.OLEDB.12.0;Data Source=" + filePathMain + ";Extended Properties=\"Excel 8.0; HDR=Yes;\";");
  
          // Opening The Connection With The Excel File
          MyConnection.Open();
  
          // The Connection Gets MyConnection
          myCommand.Connection = MyConnection;
  
  
      }
  
  public static void closeMyConnection()
      {
          MyConnection.Close();
  
      }
  </code></pre>
  
  <p>Anyone have any suggestions?</p>
  
  <h2>Exact Error Code</h2>
  
  <hr>
  
  <p>System.Data.OleDb.OleDbException (0x80004005): Number of query values and destination fields are not the same.</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object&amp; executeResult)</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&amp; executeResult)</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object&amp; executeResult)</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)</p>
  
  <p>at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()</p>
  
  <p>at MyExcel_IO.Excel_IO.inSertRowTEST(String FP1, String TableName) in c:\Users\t1008ts\Desktop\Projects\MasterP2\May19Template\Excel_IO.cs:line 220</p>
  
  <h2>   at MyExcel_IO.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\t1008ts\Desktop\Projects\MasterP2\May19Template\Form1.cs:line 121</h2>
  
  <h2>OK</h2>