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