title: Export sql server table structure with data programmatically using C#
body: <p>I have a table with data in sql server. I need to take the backup of that table structure as well as data into some sort of file programmatically using <code>C#</code>. May be <code>.sql</code> extension file. Same way as we do using <code>Task</code> option in sql server management studio.</p>
  
  <p>I googled it but did not find anything related to this. If anybody suggest me any link will be highly appreciated.</p>
  
  <hr>
  
  <p>(Edited in from comments)</p>
  
  <p>The backup is for safety purpose. As I am going execute the conversion logic for one of my scheduler control. The process is: </p>
  
  <ol>
  <li>Get the backup of the table data into a list.</li>
  <li>Truncate the table. </li>
  <li>Convert the data to desired format.  </li>
  <li>Insert the converted data into the same table.</li>
  </ol>
  
  <p>If any conversion logic problem, I can fix it later using the backup file.</p>