Code string connectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString(); SqlConnection connection =new SqlConnection(connectionString); connection.Open(); // Perform an initial count on the destination table. SqlCommand commandRowCount =new SqlCommand("CREATE TABLE #helloworld([Serial_No] [nvarchar](100),[Product_Code] [nvarchar](100)) SELECT COUNT(*) FROM "+"#helloworld", connection); long countStart = System.Convert.ToInt32(commandRowCount.ExecuteScalar()); Console.WriteLine("Starting row count = {0}", countStart); // Create the SqlBulkCopy object. // Note that the column positions in the source DataTable // match the column positions in the destination table so // there is no need to map columns. using (SqlBulkCopy bulkCopy =new SqlBulkCopy(connection)) { bulkCopy.DestinationTableName ="#helloworld"; try { // Write from the source to the destination. bulkCopy.WriteToServer(dt); SqlCommand commandRowCountAll =new SqlCommand("select h.Serial_No,p.Product_Code,p.origin,p.warehouse_code,h.Product_Code AS PRODUCT_CODE_ERROR from #helloworld h left join TB_PRODUCTINFORMATION p on h.Serial_No = p.SERIAL_NO and p.PRODUCT_CODE like h.Product_Code+'%'", connection); DataTable datatable =new DataTable(); new SqlDataAdapter(commandRowCountAll).Fill(datatable); return datatable; } catch (Exception ex) { Console.WriteLine(ex.Message); returnnull; } }