Video: Working with DataSets
This is my first attempt at making a screencast. I hope to make a small series over the coming weeks, each showing how we can work with data binding to improve our applications. This one took about half an hour to prepare, 5 hours to revise (I attempted to record it about 15 times!), and another 2 hours to render to WMV.
This first episode is all about DataSets. In it, I cover:
- What are DataSets?
- Strongly typed DataSets
- Strongly typed DataAdapters (TableAdapters)
- Handling GUID default values in DataRows - a hacky workaround
- How they all work under the hood
- Partial classes and DataSets
- Coupled and decoupled DataSets and my approach
- Wiring up TableAdapters to SQL Stored Procedures
- Hippopotami
Download:
- Video: Binding Patterns 0×0001 - Working with DataSets.wmv (90 MB)
- Code and slide deck: Binding Patterns 0×0001 - Working with DataSets.zip (3.72 MB)
Links from the show:
- Corneliu’s VSAddins: http://www.acorns.com.au/projects/vsaddins/
- Hippopotami: http://en.wikipedia.org/wiki/Hippopotamus
This episode goes for about 1 hour and 15 minutes, which I think is perhaps a little long. I don’t think I could condense it into little 10 minute episodes, because with Data Binding, “the devil is in the details”. I might try to keep the rest down to about half an hour though. What do you think?
Suggestions? Feedback? Bugs? Email me at paul@paulstovell.net.
Filed under: Binding

Hi Paul, glad that you are trying out Video format but yeah, 90MB is probably beyond my “care” limit. I reckon
size is a little to large
Hey Paul,
Great entry-level introduction to DataSets!
I’m about 55 minutes in where you’ve talked about ways to initialize Guid columns in typed DataSets, and I see that you’re doing it from the UI (in the DataGridView’s NewRowNeeded event). I believe i have a better way - see what you think:
DataTable has an event called TableNewRow, which gives you the ability to assign values to columns when a new row is created.
Like any public event, TableNewRow has a corresponding protected virtual method called OnTableNewRow. You can override that in your “own half” of the DataTable’s partial class. You end up with this sort of thing:
protected override void OnTableNewRow(System.Data.DataTableNewRowEventArgs e)
{
base.OnTableNewRow(e);
e.Row.HippopotamusID = Guid.NewGuid();
}
Now, there’s one caveat with this approach. Unlike other OnXxx methods, the OnTableNewRow method is *not called* if the TableNewRow event has not been handled! So there’s one more thing we need to do within our DataSet: handle the TableNewRow event. The easiest place to do this is in the table’s EndInit method, like this:
public override void EndInit()
{
base.EndInit();
TableNewRow += delegate(object sender, DataTableNewRowEventArgs e) { };
}
This approach works a treat, and confines the initialization of the Guid to the DataSet itself, rather than relying on the “user” of the DataSet (ie the UI) doing it for you.
Matt
ps. That code was from memory - looking at it now, I think that “e.Row” is of type DataRow, rather than HippopotamiRow, so you’ll probably need to reference your column the old-fashioned way - e.Row[”HippopotamusID”].
That’s an awesome tip Matt, thanks heaps.
I’d looked at the OnTableNewRow method on the table before and I’d set a breakpoint, but it never got hit so I assumed OnTableNewRow didn’t get called until after the row was validated. Adding that code to EndInit seems to work just dandy.
Introduction to DataSets
Paul Stovell brings us the first episode of his new screencast series, ” Binding Patterns “, entitled
Introduction to DataSets
Paul Stovell brings us the first episode of his new screencast series, ” Binding Patterns “, entitled
Paul, I really enjoyed this and thought it was quite well done.
A few um’s too many which is going to be hard to work out of the presenting skills.
The size was a little large as well, I did read somewhere that with camtasia you can set it to record only say every 5th frame, audio is continuous and reduces the size massively.
Too Many Links (8 Feb 2007)
.NET, C#, VB.NET IDesign WCF Coding Standard Working with Custom Providers How to write a loading circle
Hi Paul,
Great introduction to Datasets. I could have done with this when I started a while back.
I’d agree that the length is a little too long…but I suspect 10 mins may be too short. What can you get done in 10 mins that is really useful. You’d have to watch 2-3 segments to see how to do something from end to end.
Why not break it into three sections of around 25 mins?
Great job! What a great way to explain something that takes some time to understand. Watching someone else code and hearing your though process really gave me a new way of approaching projects.
Thanks again
Looking forward to the next series!
Hi Paul,
I tried to use the partial class method to add a new data column to a row like you mentioned in this screen cast. However it doesn’t work. It tells me that it cannot bind to that column. Is there a step I’m missing… Doing a quick google tells me that I need to add it to the class descriptor or something?
Any ideas?
Cheers.. Humphrey
[…] Binding to DataSets […]
[…] Binding to DataSets, and Binding to Objects, the two screencasts I created to teach Data Binding. […]
very interesting, but I don’t agree with you
Idetrorce