using System;
using System.Data;
using System.Data.SqlClient;

namespace BulkCopyOp
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			// newjobs looks just like jobs
			// but no identity column, normal column

			SqlConnection conn = new SqlConnection("server=.;integrated security=sspi;database=AdventureWorks");
			SqlCommand cmd = new SqlCommand("select * from newjobs", conn);

			SqlBulkCopy bcp = new SqlBulkCopy("server=.;integrated security=sspi;database=AdventureWorks");

			try
			{
				conn.Open();

				SqlDataReader rdr = cmd.ExecuteReader();

				// Copy the Data to SqlServer
				bcp.DestinationTableName = "newjobs2";
				bcp.WriteToServer(rdr);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine(e.StackTrace);
			}
			finally
			{
				bcp.Close();
				cmd.Dispose();
				conn.Dispose();
			}
		}
	}
}
