Android Addicted Apps Creator

August 31, 2009

SQLtoCS Class Generator – an SQL Table to C Sharp class generator.

Filed under: WPF — alin b. @ 18:47
Tags: , ,

Well, I’m back and I’m bad… as someone used to say. I’m really not that bad, but, for sure I know more. Because I’ve started to work on a new project for a customer of mine I felt the need to develop a tool to help me do stuff faster. One big pressure came from the fact that I develop this app in my free time which isn’t really that much. So while eating, sleeping, rebuilding house, staying with my wife, waiting for our unborn little girl, I managed to crop some lines of code. I also finalized reading a WPF book from start till last page. And man… I must say it again: WPF Rocks!!! Tananana it rocks.

What does this app do you ask: in nontechnical words, it does what I hate do do (repeated  work) 🙂 in technical words it creates two classes for an Sql Server table. I’ve always been a fan of nTier architecture and the way WPF and C# works it this concept pleases me. And in big lines, this program does the business layer (Business objects) of a nTier architecture. Or at least, this is what I like to think it does.

Here is a screenshot:


The classes are generated in a few seconds. Just enter the credentials for the SQL Server or SQL CE connection, select Database and the table and press the Generate button. There are a few customizable parameters: class name, collection name and the namespace. The cs classes are saved in the exe’s directory.

The program detects what keys (PK and FK) are contained by the table and generates methods based on them.There are a lot of tools that do this on the net.  I’ve tested quite a few. There was always something bothering me and this is the main reason I started doing one for myself.

Please take your time and test it. If you have suggestions, please sent it to me.

UPDATE: The application can be downloaded from here: SqlToCs

A short, bad quality Youtube presentation:

Ah,  and about that PayPal button.. hehe… Donations are never required but they are more than welcomed.


  1. I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks, 🙂

    A definite great read.. ..


    Comment by Bill Bartmann — September 21, 2009 @ 19:59 | Reply

  2. Thanks! Great.

    Comment by Ý from vietnames — November 10, 2010 @ 08:24 | Reply

  3. This program gives me an error after I select the Table from the drop down. Any ideas?

    Comment by David — April 8, 2011 @ 14:52 | Reply

  4. Very nice tool

    I think you have a bug, when you create a collection, your code does not generate the reader.close();

    hope it helps ya

    Comment by Leopoldo Rodriguez — May 27, 2011 @ 09:26 | Reply

  5. Hi Alin,

    First of all great work. You class generator works quite good. I was able to insert a sample record via web application. I have some suggestions.

    1- You have to add nullable types correctly for non string values:
    i.e: for a boolean field:

    _IsActive =reader.IsDBNull(5) ? null : reader.GetBoolean(5)

    reader.IsDBNull(5) ? (bool?)null : reader.GetBoolean(5);

    also you have to correct property definitions too:

    private Boolean? _IsActive;
    public Boolean? IsActive
    get { return _IsActive; }
    _IsActive = value;
    OnPropertyChanged(new PropertyChangedEventArgs(“IsActive”));

    2- You have to take care of identity fields too. Because when you try to insert a record to a table which has identity insert is on you must not send the column to insert statement

    3- And instead of putting insert statements inside the class, you have to generate them as stored procedures and use in your classes.

    Again thank you much for this type of work.


    Comment by Onur — December 25, 2011 @ 16:20 | Reply

  6. This doesn’t seem to work with SqlCe. The app says the password is wrong and there is no way to enter a password. If I use the connection string, the app says the file location is invalid.

    Comment by Daimao — January 9, 2012 @ 18:15 | Reply

  7. Unfortunately, this project is discontinued since first version 🙂 So I can’t really tell you what’s wrong…

    Comment by alinberce — January 9, 2012 @ 18:49 | Reply

  8. If anyone wants the source code of this project, please drop a comment I’ll try to search/send it.

    Comment by alinberce — January 26, 2012 @ 14:15 | Reply

    • yeah, i would love to. onuromerozturk at gmail dot com.

      Comment by Onur Ömer Öztürk — January 26, 2012 @ 14:33 | Reply

  9. Sources sent

    Comment by alinberce — January 30, 2012 @ 20:24 | Reply

  10. Hi,
    I think that’s just what I need. Can you send me source code, because I want some things a bit to adjust to my needs.

    Great job, thank you.

    Comment by Marko — February 1, 2012 @ 16:16 | Reply

    • Yes, great job!

      Comment by Andrew — February 1, 2012 @ 18:29 | Reply

      • Yes look very good Alin, can you send the code to me too?

        Comment by cocis48 — February 7, 2013 @ 22:51

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: