Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 19-24 extracted from chapter ADO.NET 2


Listing 19-23<     > Listing 20-1


This listing can be compiled with the command line:
csc.exe /target:exe Example_19_24.cs
Errors: 0 Warnings: 0


Example_19_24.cs
using System.Data;
using System.Data.SqlClient;
class Program {
   static string sCnx = 
      "server = localhost ; uid=sa ; pwd =; database = ORGANIZATION";
   static string sCnx2 = 
      "server = localhost ; uid=sa ; pwd =; database = ORGANIZATION2";
   static void Main() {
      using (SqlConnection cnx = new SqlConnection(sCnx)) {
         SqlCommand cmd = new SqlCommand("SELECT * FROM DEPARTMENTS ",cnx);
         cnx.Open();
         SqlDataReader rdr = cmd.ExecuteReader();
         // Bulk copy of N_ROWS rows.
         using SqlBulkCopy bulkCopier = new SqlBulkCopy( sCnx2 ) ) {
            bulkCopier.DestinationTableName = "DEPARTMENTS";
            bulkCopier.WriteToServer( rdr );
         // end using bulkCopier;
      // end using cnx.
   }
}	
Copyright Patrick Smacchia 2006 2007