Programmatically Generate Typed DataSets
As perhaps you may have gathered from my DataSetSource post, I think typed DataSets are the bee's knees. As a general coding practice, I like to write the code-behind-the-code, rather than the code itself, and typed DataSet's allow me to do this, so I like them very much. That being said, they took a big hit with Visual Studio.NET 2005. I don't know why exactly, perhaps because of deadlines, the typed DataSet creator in VS 2005 has a few problems. I've had it fail to import relations, fail to find new columns, and even dragging a DataTable to a new location can take 15-20 seconds in a large dataset! All in all, VS 2005 was a step backward for this particular tool.
In order to continue using these wonderful classes, despite the idiosyncrasies of the new tool, I've created my own typed DataSet generation utility. It queries the schema of a SQL DB, allows you to select which tables you want to export, then creates the appropriate .vb and .xsd files. Best of all, having the source code, it can be modified to be scripted (perhaps as part of a build script?), run as often as necessary, and modified to suit particular tastes. For example, I have turned GetChildRows() into a property, and used Nullable(Of T) to represent null values, instead of the old "IsMyCollumnNull()" methods.
It's called the "Enhanced Generator of Advanced Data Sets", and it looks like this:

To use it, simply:
- Enter the path you want it to create its classes under
- Enter the connection string to your database
- Enter the DataSetName you want your new dataset to be called
- Click "Get Tables" - select the tables you want
- Click "Generate"
Please Note:
- Note that this code is for example purposes only, its meant as a base for you to develop off of, and an example of how to use the CodeDom
- You may need to delete / rename / exclude the .xsd file, because Visual Studio tends to want to generate its own code, which will conflict with Egads
Download Egads!
Attachment(s): Egads.zip