1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. string cs = ConfigurationManager.ConnectionStrings["SchoolConnectionString"].ConnectionString;
  6. using (SqlConnection sqlConn = new SqlConnection(cs))
  7. {
  8. DataSet ds = new DataSet();
  9. ds.ReadXml(Server.MapPath("~/Data.xml"));
  10. DataTable dtStudentMaster = ds.Tables["Student"];
  11. sqlConn.Open();
  12. using (SqlBulkCopy sqlbc = new SqlBulkCopy(sqlConn))
  13. {
  14. sqlbc.DestinationTableName = "StudentMaster";
  15. sqlbc.ColumnMappings.Add("Name", "Name");
  16. sqlbc.ColumnMappings.Add("Phone", "Phone");
  17. sqlbc.ColumnMappings.Add("Address", "Address");
  18. sqlbc.ColumnMappings.Add("Class", "Class");
  19. sqlbc.WriteToServer(dtStudentMaster);
  20. Response.Write("Bulk data stored successfully");
  21. }
  22. }
  23. }
  24. catch (Exception ex)
  25. {
  26. throw ex;
  27. }
  28. }