title: Bulk insert into SQL table from CSV using C#
body: <p>I need to bulk insert data into <code>SQL</code> from a <code>csv</code> file.  In SQL I use the command:</p>
  
  <pre><code>bulk insert InputTestData
  from 'D:\Project\UnitTestProjct\RGTestingToolTestProject\NUnitTestProject\RGTestToolDB\InputTestData.csv'
  with
  (   CODEPAGE ='RAW',
      rowterminator='\n',
      fieldterminator = '\t'
  )
  </code></pre>
  
  <p>The above command is working and inserts data when using SQL query analyzer, but, throws an error when executed from <code>C#</code> using the code given below :</p>
  
  <pre><code> StringBuilder builder = new StringBuilder();
                                      builder.Append("bulk insert " + objectName + " from ");
                                      builder.Append("'" + ResourceFilePath + Path.DirectorySeparatorChar + objectPath + "'");
                                      builder.Append(" with");
                                      builder.Append(" (");                                       
                                      builder.Append(" rowterminator='\n',");
                                      builder.Append(" fieldterminator = '\t'");
                                      builder.Append(" )");
  
                                      SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, builder.ToString());
  </code></pre>
  
  <p>It throws the error: </p>
  
  <pre><code>Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 8 (IsBaselineTest).
  </code></pre>
  
  <p>The query generated by C# code is also working fine in <code>SQL</code> query analyzer :</p>
  
  <pre><code>bulk insert InputTestData from 'D:\Project\UnitTestProjct\RGTestingToolTestProject\NUnitTestProject\\RGTestToolDB\InputTestData.csv' with ( rowterminator='
  ', fieldterminator = '  ',CODEPAGE ='RAW' )
  </code></pre>
  
  <p>Please let me know if you have required <code>CSV</code> and <code>SQL</code> table structure</p>
  
  <p>Please help on above.</p>
  
  <p>Thanks in Advance</p>