Thursday, February 13, 2014

Looping over files with the Foreach Loop

In SQL Server 2000 Data transformation Services (DTS) it was a bit of a hack to be able to loop over files of a given type in a certain directory and import them into your destination. It involved a lot of "Glue Code" and a certain amount of fooling the package into going back to a previous task because it still had work to do. Well thankfully in SQL Server 2005 Integration Services (SSIS) that has all changed and this article is going to show you how.
The image below shows us how incredibly simple and clean the package will look when finished. There are some things worth pointing out at this stage. In the centre of the screen we see the Foreach Enumerator container and inside that we see the Data Flow task which houses the pipeline. At the bottom in the Connection Managers tray we see our Flat File Connection Manager (My Source File) and our OLEDB Connection Manager (My Destination). The Flat File Connection Manager is the one in which we are most interested for this article. Both of these managers are used in the Data Flow behind the DataFlow task. We will not be detailing the pipeline behind the DataFlow task in this article but it consists of a Flat File Source moving data to an OLEDB destination.
ThePackage Let's begin then by opening up the Foreach enumerator and moving straight to the Collection node in the tree on our left. Below we see our information already populated.
Collection What we see on the screen is pretty self explanatory but let's go through it anyway. We have chosen to enumerate over a file collection and ths is indicated by the value next to the Enumerator property at the top. We need to specify a folder over which to loop and for which type of files to look and we do that in the centre of the form. We are given three options as to what is returned when the loop finds a file in the folder at the bottom of the form. We can return the whole filename including extension and path, the name and extension or simply the name of the file found. Because our connection manager is going to need to know exactly where to find the file and it's name we have hosen the first option. The final thing we see on this screen is the ability to traverse subfolders. In our example we do not need to do this.
When the Foreach enumerator finds a file it needs to tell us about what it found and it does this by populating a variable. Click on to the Variable Mappings node now. Our package currently has no variables able to accept the name of the file so we are going to create a new one.
VarMapping The next screen we see allows us to set the values of the variable. As we can see variables can be scoped in SSIS to certain executables in the package or to the package itself.
Scoped Here is how our variable looks with all its properties set.
FileFound Because the enumerator will only return us at most one value on every iteration we map our variable to an index of 0.
Mapped We have now configured everything as far as the Foreach enumerator is concerned. We now need to set the rpoerties of the Flat File Connection Manager. Highlight the manager in the tray at the bottom, right click and choose properties.
FilePropBefore The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column drop the list down and choose ConnectionString
Ex1 Now hit the ellises button to the right and we are taken through to the expression editor where we will build the actual expression itself.
Ex2 Our requirements are pretty simple here and all we want to do is to retrieve the variable we defined earlier. To do this simply drag the variable from the list at the top to the expression text box at the bottom. Property Expressions can become very complex and we shall no dount be seeing more of them in future articles. After you have chosen the variable click OK
Ex3 We now see that our expression is mapped to our ConnectionString property. Click OK
Finally we can now see our File Manager's Connection string property being mapped to an expression in the properties of the manager.
FilePropAfter That's all there is to it. When the enumerator finds a file matching our requirements it will set the correct property on the connection manager and this will be used by the pipeline at runtime.

Source: http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx

Tuesday, February 11, 2014

String.Format in C#

Console.WriteLine("Standard Numeric Format Specifiers");
String s = String.Format("(C) Currency: . . . . . . . . {0:C}\n" +
                    "(D) Decimal:. . . . . . . . . {0:D}\n" +
                    "(E) Scientific: . . . . . . . {1:E}\n" +
                    "(F) Fixed point:. . . . . . . {1:F}\n" +
                    "(G) General:. . . . . . . . . {0:G}\n" +
                    "    (default):. . . . . . . . {0} (default = 'G')\n" +
                    "(N) Number: . . . . . . . . . {0:N}\n" +
                    "(P) Percent:. . . . . . . . . {1:P}\n" +
                    "(R) Round-trip: . . . . . . . {1:R}\n" +
                    "(X) Hexadecimal:. . . . . . . {0:X}\n",
                    - 1234, -1234.565F);
Console.WriteLine(s);
 
 
 
Example output (en-us culture):
(C) Currency: . . . . . . . . ($1,234.00)
(D) Decimal:. . . . . . . . . -1234
(E) Scientific: . . . . . . . -1.234565E+003
(F) Fixed point:. . . . . . . -1234.57
(G) General:. . . . . . . . . -1234
    (default):. . . . . . . . -1234 (default = 'G')
(N) Number: . . . . . . . . . -1,234.00
(P) Percent:. . . . . . . . . -123,456.50 %
(R) Round-trip: . . . . . . . -1234.565
(X) Hexadecimal:. . . . . . . FFFFFB2E


Source: http://stackoverflow.com/a/15168787/1295466

Thursday, February 6, 2014

10 Programming Languages You Should Learn Right Now

"One of my mentors once told me that a programming language is just a programming language. It doesnt matter if youre a good programmer, its the syntax that matters," Tim Huckaby, CEO of San Diego-based software engineering company CEO Interknowlogy.com, told eWEEK.
However, Huckaby said that while his company is "swimming" in work, hes having a nearly impossible time finding recruits, even on the entry level, that know specific programming languages. "Were hiring like crazy, but were not having an easy time. Were just looking for attitude and aptitude, kids right out of school that know .Net, or even Java, because with that we can train them on .Net," said Huckaby.
"Dont get fixated on one or two languages. When I started in 1969, FORTRAN, COBOL and S/360 Assembler were the big tickets. Today, Java, C and Visual Basic are. In 10 years time, some new set of languages will be the in thing. …At last count, I knew/have learned over 24 different languages in over 30 years," Wayne Duqaine, director of Software Development at Grandview Systems, of Sebastopol, Calif., told eWEEK. By picking the brains of Web developers and IT recruiters, eWEEK selected 10 programming languages that are a bonus for developers to add to their resumes. Even better, theyre great jumping-off points, with loads of job opportunities for younger recruits.

1. PHP



  • What it is: An open-source, interpretive, server-side, cross-platform, HTML scripting language, especially well-suited for Web development as it can be embedded into HTML pages.
  • Why you should learn it: Its particularly widely used. "High-speed scripting with caching, augmented with compiled code plug-ins (such as can be done with Perl and PHP) is where the future is. Building Web apps from scratch using C or COBOL is going the way of the dinosaur," said Duquaine.
  • Job availabilities: 1,152*

  • 2. C#
  • What it is: A general-purpose, compiled, object-oriented programming language developed by Microsoft as part of its .NET initiative, it evolved from C and C++
  • Why you should learn it: Its an essential part of the .Net framework. "Learning C#, which is just Java with a different name plate, is critical if you heavily use Microsoft," said Duquaine.
  • Job availabilities: 5,111

  • 3. AJAX (Asynchronous JavaScript and XML)
  • What it is: Though technically not a programming language, AJAX uses XHTML or HTML, JavaScript and XML to create interactive Web applications.
  • Why you should learn it: Ever since Google Maps put AJAX, well, on the map, the requests for AJAX-knowledgeable pros went through the roof. "The demand for AJAX knowledge is huge because its so damned hard to learn," said Huckaby. Of note, Microsoft announced recently plans to release a tool named Atlas that will make AJAX easier to implement. "If Microsofts Atlas tool is successful, it would bring the extreme complexity and annoyance of AJAX to the average worker," said Huckaby.
  • Job availabilities : 1,106

  • 4. JavaScript
  • What it is: Not to be confused with Java, JavaScript is a an object-oriented, scripting programming language that runs in the Web browser on the client side. Its smaller than Java, with a simplified set of commands, easier to code and doesnt have to be compiled.
  • Why you should learn it: Embedded into HTML, its used in millions of Web pages to validate forms, create cookies, detect browsers and improve the design. With its simplicity to learn as well as wide use, its considered a great bang for your educational buck.
  • Job availabilities: 4,406

  • 5. Perl
  • What it is: Perl is an open-source, cross-platform, server-side interpretive programming language used extensively to process text through CGI programs.
  • Why you should learn it: Perls power in processing of piles of text has made it very popular and widely used to write Web server programs for a range of tasks. "Learning some form of scripting language, such as Perl or PHP is critical if you are doing Web apps," said Duquaine.
  • Job availabilities: 4,810

  • 6. C
  • What it is: A standardized, general-purpose programming language, its one of the most pervasive languages and the basis for several others (such as C++).
  • Why you should learn it: "Learning C is crucial. Once you learn C, making the jump to Java or C# is fairly easy, because a lot of the syntax is common. Also, a lot of C syntax is used in scripting languages," said Duquaine.
  • Job availabilities: 6,164, including all derivatives

  • 7. Ruby and Ruby on Rails
  • What they are: Ruby is a dynamic, object-oriented, open-source programming language; Ruby on Rails is an open-source Web application framework written in Ruby that closely follows the MVC (Model-View-Controller) architecture.
  • Why you should learn it: With a focus on simplicity, productivity and letting the computers do the work, in a few years, its usage has spread quickly. As a bonus, many find it easy to learn.
  • Job availabilities : 210 and 54, respectively

  • 8. Java
  • What it is: An object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s.
  • Why you should learn it: Hailed by many developers as a "beautiful" language, it is central to the non-.Net programming experience. "Learning Java is critical if you are non-Microsoft," said Duquaine.
  • Job availabilities: 14,408

  • 9. Python
  • What it is: An interpreted, dynamically object-oriented, open-source programming language that utilizes automatic memory management.
  • Why you should learn it: Designed to be a highly readable, minimalist language, many say it has a sense of humor (spam and eggs, rather than foo and bar), Python is used extensively by Google as well as in academia because of its syntactic simplicity.
  • Job availabilities: 811

  • 10. VB.Net (Visual Basic .Net)
  • What it is: An object-oriented language implemented on Microsofts .Net framework.
  • Why you should learn it: Most argue that VB.Net is currently more popular than ever and one of the only "must-learns." "It is currently dominating in adoption and that is where all the work is," said Huckaby.
  • Job availabilities: 2,090

  • Source: 
    http://www.eweek.com/c/a/IT-Management/10-Programming-Languages-You-Should-Learn-Right-Now/

    Wednesday, December 11, 2013

    Is Programming Easy To Learn? - Bjarne Stroutstrup

    The second part of an interview with Bjarne Stroustrup showed up last week. (I talked about part one earlier.) One of the questions he was asked was if we should be "simplifying the process of coding so that more individuals are able to participate in development?" Stroustrup's answer is interesting and in two parts. Both parts are ripe for discussion. The first part of his answer is that "The idea of programming as a semiskilled task, practiced by people with a few months' training, is dangerous." The second part should be very interesting to those of us trying to teach programming - "I don't think it is true that the programming languages are so difficult to learn." He basically says that most other academic subjects are more complex, have more detail and are harder to learn. Interesting.
    I go back and forth about the idea of a lot more people being able to do their own programming. There I times when I think just about everyone should be able to develop their own code for specific applications but that they need some easier tools to use. There are other times when I think we have way too many programmers who don't really know what they are doing already. The ideal is probably somewhere in the middle. I do think that we have to make it easier for more people to do more with their computers than they do now. Does that necessarily mean they will or should be programming? That is unclear.
    The idea of programming being easier to learn than other academic subjects again is - maybe so maybe not.  I do believe that programming language syntax is not all that complex. Really it's not. Compare it to the weird stuff that goes into calculus or the complexity of learning another natural language or even the correct order of events in a history class. What is difficult about programming is the mind set - the thought process that goes into developing a program. That is what takes a while to teach.
    That being said the art of teaching programming involves teaching the syntax and language structure at the same time one is teaching the planning and thought process that is involved in actually doing programming. Learning a second or third programming language is often a fairly trivial process for most people. The hard part is constant (mostly) while only the easy part (the syntax) changes. This is why tools like Alice, Squeak and Scratch are so popular - they allow teaching of programming concepts without the complexity of (the easy part) language syntax. Programming maybe the only discipline where we teach the hard part first and then come back to the easy part.
    The hard part of programming is not programming languages but programming thinking. We may use other tools to avoid the more involved syntax of most programming languages at the beginning but there is real power in them so eventually people have to learn them. They really shouldn't find the languages all that difficult. It's not rocket science after all.  And oh by the way they taught rocket science in my high school 35 years ago.
    I maintain that the real problem with learning programming is poor teaching and poor teaching tools. I do not exempt myself from that poor teaching either. I often think that a lot of my students succeeded in spite of my teaching rather than because of it. If I'd done things differently maybe programming would have "clicked" for more of them. Maybe more of them would be writing code to change the world. We should be spending some of the money we are spending on new programming languages and put it into finding new and better ways to teach what really should be a moderately difficult rather than extremely difficult course of study.
    What do you think?

    Source: blogs.msdn.com

    What is a class?

    One day on my class, I asked a question to students, What is a class? Everyone came up with a definition. One popular definition was "A class is a group of objects". I stunned at this answer. This was a definition stated in text book.
    I started to explain the definition, "A class is s group of objects". I showed them a pen and told them that the pen is an object. All agreed. Then I showed three pens, so a group of pen, a group of objects.
    If so, then the three pens should be called as a class.

    Huh..

    It is not. It is absolutely wrong understanding....

    Then what is a class..

    A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.

    I need to explain this further.

    For example, take any object say a table. It has so many characteristics. Let me specify some of those.
    1. Color of the table.
    2. Size of the table.
    3. Price
    4. No. of Legs.
     These are the properties or attributes of a table.
    So we can form a class like the following

    Class Table{
    • Color
    • Size
    • Price
    • NoOfLegs
    }



    Tuesday, December 10, 2013

    Are you a kid in programming?

    I was also a kid in programming. Going through a lot of serious preparations, I learned a lot of things from books(e-books) than from instructors. Thanks to all sources who provides free e-books to download.

    I personally like to recommend two books for the beginners to get started up. First, a book of your language from Head First Series and second a book of your language from How to Program Series.

    Welcome to all learners

    Hi,

    I would like to share all my experiences in programming through this blog. Novices can use this blog to get good understanding about the core concepts in programming like oops etc.,