Drawing Boxes and Line with the DataSet designer

Drawing Boxes and Line with the DataSet designer

  • Comments 4

           One of the neat things about working on Visual Studio is that it is such a big and rich product that I’m always being clued into both new interesting features and old features that I have just missed up until now. I was recently working on some squarified treemap UI prototyping and I was coding up a DataSet to hold the basic data for my view. I don’t have any ADO.net experience so I was just pulling stuff together with the MSDN entries for DataSet, DataTable and DataColumn open in a few IE windows. After asking a question about table relations of a colleague of mine, he pointed out to me that Visual Studio already has designer support for DataSets and suggested that I take a look at it.

 

            A lot of my fellow team members (and a lot of programmer in general) are pretty down on the idea of designers. They roll their eyes at the thought of some programmer in the future (probably using some type of Minority Report style goofy 3D input device ;) ) connecting little boxes with lines to somehow magically create fully featured applications under the surface. And to be honest, they have some pretty good points; we are certainly a long way off from designers becoming some kind of programming mainstay. But in my experience, designers have been making some great improvements over the last few years. I’ve found them useful in two particular scenarios. First, they can be useful when you do not have experience in the designer domain and they can help guide your design. And secondly, they can be useful when they are restricted to a small set of the overall application. For instance, UI designers have been catching on recently not only because UI lends itself to visual layout (and it does), but because it’s looking at a small subset of the total application code.

 

            The DataSet designer does meet both of the above criteria, as I am not experienced with datasets and it is dealing with a restricted subset of the total application code. So next I’ll show you a quick walkthrough of how I used the DataSet designer in my application. Adding a new DataSet designer component to your project is as simple are right clicking the project, selecting “Add new item” from the context menu and then selecting DataSet in the screen shown below.

 

 

            After creating the new DataSet you will have a new designer space opened up for you in your IDE (shown below). Also, you should have your Toolbox window open so that you can drag in the various components for your DataSet.

 

 

For my simple app, I have a started out with the TreeMapBaseData table that holds a bunch of information about commands that are being logged. Creating the table was a simple as dragging it from the Toolbox out onto the designer surface. For the columns I simply right clicked on the table and selected add new column.  To edit values for the columns I used the property sheet shown below. By setting the CommandID columns to be unique = true it automatically showed up as the key column for my table as I intended (you can also add and remove keys from the designer).

 

 

            My next step was to create the TreeMapCommandData table. My goal for this table was for each unique “Command” string in the TreeMapBaseData table to have a TreeMapCommandData row that stored the count of instances of that command and the sum of the execution times of that command. My first step was to drag on a new table and add the appropriate column names, with the “Command” column set to be the key by marking it unique.  Next I needed to build a relation between the two tables. By selecting the TreeMapCommandData and then dragging a relation onto TreeMapBaseData I was presented with the Relation dialog box shown below. Since Command was the “one” in the one-to-many relation I set it as the parent table and linked up the “Command” column.

 

 

            Now that I had my two tables and the relation between them defined the final step I needed for my DataSet was to define the sum and count columns for TreeMapCommandData. To do this I just added the appropriate expressions into the expression fields of the TotalExecutionTime and NumberOfCalls columns. For example the TotalExecutionTime column contained the following expression “Sum(Child(CommandRelation).ExecutionTime)” where CommandRelation was the name of the relation that I created between the two tables.

 

            Now that I constructed the DataSet I was able to access all the elements programmatically through my code. For example I could replace a statement like:

 

                 myDataSet.Tables[“TreeMapCommandData”].Columns[“CommandID”];

 

            with:

 

                 myDataSet.TreeMapCommandData.CommandID

 

            Plus you get the free Intellisense support, which is very nice to have.

 

            So in review I have pretty positive feelings about using the designer to create my DataSet. I’m sure that if I was a veteran ADO.net guru, I would probably find it more annoying, but for a novice it was a pretty sweet tool. This quick example is probably the best experience I’ve ever had with a designer, perhaps there is some hope for connecting boxes and lines in the future after all ;).

  • It's funny we just had a conversation about designers in IDEs at work. And on the whole I agree with the coding masses who shun designers. But you're right about when designers are useful. And now that I think about it, I use coding helpers all the time, auto generating accessors, inline syntax completion, intellisense... and I couldn't imagine coding without them, it's what makes a modern IDE, well modern. If you squint your eyes and catch it in your peripheral vision these could also be considered designers, just in a VERY limited scope.

    Even designers with a broader scope are useful, especially as you said when you aren't experinced in the designer's domain. They make getting an app up and running a snap (did somebody say winforms??). Granted designers have to make some assumtions at some point, and that is sure to show in the code, but if all you want is a test harness, or you're a DBA who just needs a quick reporting app, then great, use the designer.

    With these quick apps I believe is where the rub lies. A designer by nature paints with a somewhat broad brush, thus the code generated most likely won't be as efficient or as pretty as an expert could do.

    Designers are just another tool in the belt, they won't do everything, but they are still useful. In summary, I agree with you Ian, and nice job on the post. I always look forward to seeing what you'll have on here next =]
  • I'm just curious at your overall approach to the design.

    When starting with a data designer such as this, or straight SQL, the design is very data centric. Do you find you took this approach because you had a data-centric design in mind? Is there any reason you didn't go with an OO approach? If you were to go with an OO approach how different would it look? Finally, what tools would you have used if you started with an OO design?

    These are the questions I'm struggling with as of late. I prefer to design using OO techniques, but ultimately all the data I deal with is stored in a database, so ignoring a data centric design approach isn't practical.
  • PingBack from http://insomniacuresite.info/story.php?id=4191

  • PingBack from http://thestoragebench.info/story.php?id=1413

Page 1 of 1 (4 items)