C# DataSets and the Magic of ReadXML

Jan
31
2008

I've worked on several applications where we used .NET DataSets as the container for passing records between web services and other components. They work pretty well to keep things nice and loosely coupled when you're building lots of separate components that may or may not all be using the same language, etc.

One of the greatest things that they included in the DataSet classes is the ability to read and write them to XML files. That gives you not only an interchange format, but a file-based version of it pretty quickly. You can easily use those files as your "gold standard" for building all of the components at once. As long as each component emits and consumes that sample file, things are golden.

Anyway, one of the side benefits of that ability to read/write those XML files is that it not only handles the DataSets you create via code. The ReadXml() method actually will convert nearly any XML file into a DataSet. That can come in really handy when your entire application is already passing DataSets around.

That's because nearly any application of reasonable size pulls in information from somewhere outside of the control of your code. In many of those cases, that data will be in XML format. You can, therefore, use the ReadXml() to get DataTable access to all kinds of useful XML stuff.

When it gets read in, .NET does some pretty cool automatic stuff, like creating identifier columns on your tables, etc. However, if, unlike the "normal" DataSets, your imported XML data is nested 2-3 or more levels deep, it can be kind of hard to predict exactly what the DataTable structure will look like.

I'm not a huge fan of automatic or "magic" methods, because you usually have absolutely no way to see inside the black box. That's not the case here because, while the method does some pretty cool magic, it is still possible to see inside of what it does.

I decided that I needed something to deal with the black box today and after dinner tonight, I wrote a quick console app to take an arbitrary XML file and dump out all of the tables, columns and rows in the DataSet in a way that makes it more clear how you'll need to use the tables to grab the data you're after.

That's the information you're going to need to establish your DataRelation objects to tie things together. It's been fairly illuminating for the few files I've sent through it so far and I'm thinking this will be a permanent part of my utilty folder.

I run it using Powershell and the "Out-File" pipe the output to a file, giving me a record of that schema (which I find much easier to read than the output of the WriteXmlSchema() method).

In case you'd like to use it as well, here's a copy of the code.

Make It Yourself: Croutons

Jan
24
2008

When I mentioned over the holidays that the croutons on our Christmas salad were actually homemade (in response to a question on the brand), I was met with more surprise than I expected. Unfortunately, that response is something I've heard from lots of other people who actually make their own stuff, from food to robots.

The last 100 years of manufacturing, particularly the last 60 or so, have rendered the bulk of several generations incapable of seeing certain items as anything other than the result of factory production.

For food, that means that really simple items like croutons and whipped cream, when made instead of bought generate incredulity. It's as though those items have been moved from the class of things you can make yourself into the class of things you pay $3 for in the grocery store in a hermetically sealed container that's been on the shelf or in the refrigerator for 6 weeks or 6 months.

Fortunately, the whole "Maker" movement is helping to rectify some of this problem. Lots of people are taking these matters back into their own hands and discovering the joy of having made this stuff yourself as well as products that end up at a higher quality standard than the stuff plopping off the end of the Kraft factory line.

Anyway, last night, the homemade crouton supply was running low, so I made up another batch. I had the small digital camera in my pocket, so I took a few shots while I made them and strung them together early this morning into a quick slideshow and put the video up.

The croutons themselves look a little dark in the photos, but they taste great.

My Rant on Making Money in Podcasting

Jan
22
2008

This weekend, Dave Slusher expressed frustration in trying to explain why most of the arguments related to money in podcasting seem to miss the point. I wrote what was originally going to be a 140 character Twitter post (no, I will not use the tw**t word) that ended up being 2 longish emails instead.

He thought it was worth sharing with others and said so. I try to minimize the amount of meta, "blogosphere" stuff on this site. That whole frothy, new media world where everyone has accounts on Flickr, Twitter and Facebook , subscribes to podcasts and hangs on every word from Steve Jobs' mouth is just something that I don't have much interest in.

So, I gave him the go-ahead to put it up on his site. In case you're curious, you can read it here.

Running The Numbers on Wholesale Consulting

Jan
22
2008

Every once in a while, someone asks me about the numbers behind doing contract/wholesale consulting. They usually aren't asking about specific figures, but are curious about how the numbers fit together. Because there's so much information out there about how to figure out pricing on retail consulting, I figured I'd share a bit on wholesale.

First, to make the numbers easier to work with (and keep the focus on the principles instead of the actual dollar figures), let's invent a currency where you could live comfortably on 2000 of it per month. And, since this is my little invented world, we'll use the "J" as the symbol. Apply whatever exchange rate you want to it to get dollars.

So, let's say you've got a nice, comfortable job making 2000J a year and are thinking of going into contract work.

Read the rest of this entry »

The Ghost of Johnny Cash Haunts my Zune

Jan
18
2008

As I mentioned a few days ago, I got a Zune for the holidays from the consulting firm I'm subcontracting through. I've had it for a few weeks now and it's a decent enough device. But, there's this strange behavior that leads me to the conclusion that the ghost of Johnny Cash haunts my Zune.

I added about 20GB of my favorite music to the Zune, including 2 Johnny Cash albums. Now, I've got your basic Super Deluxe Pattern Recognizer (SDPR) installed in my skull, otherwise known as a standard human brain. As such, when a strange pattern of Boy Named Sue and Ring of Fire started popping up in the midst of nearly every listening session, I couldn't help but notice.

Fully aware of the fact that my (and your) SDPR tends to fabricate patterns in the absence of real ones, I chalked it up to strange, but random behavior. Even when I tracked such streaks as 5 out of 8 songs coming from the Man in Black.

Then, I got sick of it and decided to pull the albums off. I figured if I ever got the craving to hear "I shot a man in Reno, just to watch him die", I could just put them back on. That's when things got strange.

I've since attempted to remove the albums themselves, the individual tracks, all songs by artist, etc. And yet, the stream of Johnny Cash inclusions in shuffle mode continues.

So, I give up. This thing must be haunted and I'm just going to have to live with the ghost.

« Older Entries  

J Wynia

For better or worse, I'm the guy who runs things here. I'm a web consultant, software developer, writer and geek from Minneapolis, MN. This site is a fairly wide cross-section of the things I'm interested in and enjoy writing about.

Oh, and if you happen to be looking for hosting for your Subversion repositories or just web hosting in general, take a look at Dreamhost. It's what I use for Subversion and your signup helps me out.

Feeds and Links


www.flickr.com
This is a Flickr badge showing public photos from J Wynia. Make your own badge here.

Search


Pages

Archives

Computers Blog Directory
© 2003-2009 J Wynia. All original content is licensed under the terms of the Creative Commons Attribution license unless otherwise noted. Content from other sources is licensed under its original terms.