Ankush Singh
What is use of SQLBulkCopy Class in C#
By Ankush Singh in Windows Forms on Oct 22 2012
  • Rajanikant Hawaldar
    Oct, 2022 13

    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. }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS