///code of copy all data of emp table in other table named emp1
on button click{
SqlConnection source_conn = new SqlConnection("Data Source=BSZ123\\SQLEXPRESS;Initial Catalog=Ecom_DB;Integrated Security=True");
SqlConnection destination_conn = new SqlConnection("Data Source=BSZ123\\SQLEXPRESS;Initial Catalog=Ecom_DB;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT * FROM emp", source_conn);
source_conn.Open();
destination_conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
// Create SqlBulkCopy
SqlBulkCopy bulkData = new SqlBulkCopy(destination_conn);
// Set destination table name
bulkData.DestinationTableName = "";
// Write data
bulkData.WriteToServer(reader);
// Close objects
bulkData.Close();
destination_conn.Close();
source_conn.Close();
}
No comments:
Post a Comment