title: How to Insert whole DataTable into Sql table At once in C#
body: <p>I have excel sheet (named as $Sheet1) and sql table(named as <strong>Users</strong>) with same Formate which is given below</p>
  
  <pre><code>    ID | UserName | FirstName | LastName | DateOfBirth |
      1  | robert   | robert    | poinan   | 1984        |
      2  | joy      | joy       | rob      | 1990        |
  </code></pre>
  
  <p>I Have read the whole excel sheet data in <strong>DataSet</strong> (Named as '<strong>ds</strong>') now I want to insert the whole DataSet (which is '<strong>ds</strong>') in sql table (which is '<strong>Users</strong>')</p>
  
  <p>I am using for loop (can also use foreach loop) to insert '<strong>ds</strong>' (DataSet) rows one by one into <strong>Users</strong> (Sql table) table</p>
  
  <pre><code>sqlConn.Open();
  for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++)
                  {
  SqlCommand cmd = new SqlCommand("INSERT INTO [Users] ([ID],[UserName],[FirstName],[LastName],[DateOfBirth]) VALUES(@ID,@UserName,@FirstName,@LastName,@DateOfBirth))", sqlConn); 
  
  cmd.Parameters.AddWithValue("@ID", ds.Tables[0].Rows[i][0].ToString());
  cmd.Parameters.AddWithValue("@UserName", ds.Tables[0].Rows[i][1].ToString());
  cmd.Parameters.AddWithValue("@FirstName", ds.Tables[0].Rows[i][2].ToString());
  cmd.Parameters.AddWithValue("@LastName", ds.Tables[0].Rows[i][3].ToString());
  cmd.Parameters.AddWithValue("@DateOfBirth", ds.Tables[0].Rows[i][4].ToString());
  cmd.ExecuteNonQuery();
                      }
                  }
                  sqlConn.Close();
  </code></pre>
  
  <p>in this code I am facing a lot of problems one of these is, if there is any error in inserting the row the program stop but the rows that are inserted before are exists in the sql database next time when I try to run this program the data rows are duplicated. 
  I have millions of records. if I want to check the data row in sql table it takes a lot of time to execute the whole process.</p>
  
  <p>My quetion is. Is there any way to insert the whole '<strong>DataTable (which is in DataSet)</strong>' into <strong>Users</strong> Table at once</p>
  
  <p>Something Like This</p>
  
  <pre><code>INSERT INTO [Users](ID, FirstName,LastName,DateOfBirth) 
  SELECT ID, FirstName,LastName,DateOfBirth FROM ds.Tables[0]
  </code></pre>
  
  <p>;</p>