Beth's Chinese blog
The Visual Basic test team members in Shanghai just started translating the Visual Basic Team blog into a Chinese version and has launched it on joycode (a popular technical blog site in China where Soma's blog is also translated and published). The team members in Shanghai will pick the most technical and interesting English posts to translate and publish them there. I encourage you to keep subscribing to the English feed for up to the date announcements, but for our Chinese-only readers, this will be a very useful feed for that community. Many thanks to all the awesome people translating our posts!
Enjoy!
I blogged last week about the new face lift that the Visual Basic Developer Center got and more features keep rolling out. This week we've got feeds on the three top panels for Headlines, How-Do-I Videos, and Downloads! You can subscribe to any and all of these so you can be sure not to miss any of these content items. Of course, there's much more to see on the site and you can use it as a portal to our forums, samples, blog aggregation, troubleshooting, community articles, and much much more. And don't forget to rate the pages you read and videos you watch and provide feedback. I read every one of your comments and ratings!
I also published a new How-Do-I video today on multi-targeting and upgrading your VB 2005 projects to 2008 Beta 2 in order to enable LINQ which goes along with this blog post from last month, so check it out!
I recently convinced a friend of mine, Barton Friedland (founder of Bay.NET and rock star), to take a look at the next version of Visual Basic -- 9.0 and specifically it's implementation of LINQ to XML and XML literals. Barton is a curious as a cat when it comes to languages and I thought I could easily coax him into taking a look. Phrases like "XSLT and XQuery killer" and "most productive tool" were thrown about during the conversation and that got him hook, line and sinker.
Barton and his superhero/coworker side-kick Amy at Luminous Group in SF both started spending time learning Visual Basic 9 in the evenings. When I checked up with them last month Barton told me he was ready to start posting. Well he finally did and he's written this post and this one both on XML literals, a new unique feature of VB 9.
I'm really enjoying seeing the typical C-style programmers like Barton take a very serious look at VB.
Today .NET Rocks posted the show I did with Charlie Calvert. I really enjoyed my time with Carl, Richard and Charlie.
But I have to say that I really hate the sound of my voice over the phone, especially my laughing! Ick. And the picture they are using to promote the show.. what is THAT? So unflattering! But I guess the hand waving shows off my Italian heritage. They need to put a bottle of chianti in front of me instead of that beer!
Anyways, I should also mention that Charlie did a great presentation at Bay.NET user group last night in San Fransisco and he let me show 15 minutes of Visual Basic 9's implementation of XML literals, XML property IntelliSense and LINQ to XML. People were blown away at how productive VB is when working with XML. Thanks Charlie for letting me into a room with a bunch of C# dudes. ;-) I'll be speaking at the Pleasanton meeting next month, October 10th, on migrating your VB6 apps to .NET so please stop by if you're in town.
Recently the VB Team received a customer bug submitted through Connect that had to do with binding multiple combo boxes to the same data source. The customer was reporting that once a selection was made in one combo, the other combos were also changing. The resolution was "By Design" because of the way the customer was setting up the data binding. We thought it would benefit the community if I posted information on how we helped the customer resolve the issue, so let's talk about what was happening and the solution. But first some architectural background on data binding.
Data binding on Windows Forms involves a few different objects depending on where your data is coming from (i.e. an object or the database directly) but we're going to focus on the database scenario. The TableAdapter is responsible for talking to the database and pulling in result sets into DataTables contained in a DataSet and for sending back the updates -- this is referred to sometimes as CRUD -- Create, Retrieve, Update, Delete. The DataSet maintains the client-side representation of that data (and can also perform validation) by placing the data in DataRow objects that are contained in DataTables. The BindingSource is responsible for maintaining currency, that's the position of the DataRow in the DataTable in which the controls are displaying data from. Here's a simple diagram pulled from my How Do I video on Understanding Data.
Once you get your DataSet and TableAdapters set up you're ready to start data binding to your controls. You use the Data Sources Window to drag fields and tables onto your form and I've shown how to do this in many videos in the Forms Over Data series. When you do this, the DataSet and TableAdapters are dropped onto your form and then a new BindingSource object is created for you. It's this BindingSource that is providing the "glue" between the DataSet and your controls.
There's one video in particular that shows you how to create lookup lists. In this scenario, the data binding is a bit more complex. When you bind a textbox to a BindingSource it's a simple binding to a single field in the current row. When you bind a combo box that acts as a lookup list however, you need two binding sources because you need to be able to display the data from one lookup table and place the value into the table that you're editing.
It's very easy to set this up through the Data Sources Window. First drag all the fields you want to edit onto the from from your edit table by selecting the drop down next to the table and choosing "Details". You can change the lookup fields to combo boxes by selecting the drop down next to the fields and changing the control to a combo box:
Once you have the controls bound to your edit table you can easily bind the combo box list with data from your lookup table. Just drag the lookup table from the Data Sources Window directly over the combo box. Repeat this process for each combo box you want to display that lookup data. Then use the property window or the smart tags on the combo boxes to adjust the ValueMember (the field who's value you want placed in your edit table) and DisplayMember (the field who's value you want displayed in the combo) properties.
This will create THREE separate LookupBindingSources, (four total BindingSources once you count the edit table's BindingSource). This is the key to binding the same lookup data to multiple combo box controls. If you use the same LookupBindingSource instance for the combo boxes then you will end up in the same situation as the customer who reported the bug. If you don't use separate BindingSource instances then as a selection is made in one combo, the others also change to that value, and that's probably not the desired behavior you want.
Why this works this way is because each BindingSource object manages it's own position within the data source that is bound to it. If you use one LookupBindingSource in this example for multiple combos, then as one selection is made, the other will also change. (Keep in mind that using multiple LookupBindingSources does not load multiple instances of the LookupTable's data from the database, it just simply creates multiple BindingSource objects.)
So the customer easily fixed this issue and was very happy with the VB Team's quick response.
I was reading another installment of ScottGu's articles on his blog about using LINQ to SQL in ASP.NET with the LinqDatasource. Scott does an amazing job of explaining things very clearly so if you haven't checked his posts out already then you definitely should. It's also very nice to see him show both VB and C# code. One example that I want to point out is where he uses a Lambda Expression to get the totals for each product:
Dim products = From p In db.Products _
Where p.Category.CategoryName.StartsWith("C") _
Select p.ProductID, _
p.ProductName, _
p.UnitPrice, _
NumOrders = p.Order_Details.Count, _
Revenue = p.Order_Details.Sum(Function(details) _
details.UnitPrice * details.Quantity)
The lambda here is denoted by the "Function" keyword and it is passed to the "Sum" extension method in order to calculate the order totals for each product. In VB 9 we can also use "Aggregate" instead in this case. Additionally, we can use "Like" in the Where clause producing the following equivalent query:
Where p.Category.CategoryName Like "C*" _
Revenue = _
Aggregate detail In p.Order_Details _
Into Sum(detail.UnitPrice * detail.Quantity)
VB 9 has additional LINQ expressions that you can use instead of manually writing lambda expressions for things like Sum, Min, Max, Average, etc. I prefer the easier-to-understand VB expression syntax so I tend to use these instead. For more information on writing group and aggregate queries in VB 9 watch this video.
Just to add to the plethora of content available on LINQ, I want to point out the latest .NET Rocks! show with Don Demsak (a.k.a DonXML - XML MVP) discussing LINQ to XML and XML literals in Visual Basic. Don also did a couple shows on dnrTV (here's Part 1 and Part 2).
A very generous VB community member, Bob Schild, sent these to me to post here to share with the rest of you. Bob took many of the How-Do-I videos and created his own walk throughs for them. So if it's easier for you to learn by reading instead of listening to me speak then you'll be happy to have these by your side.
Please feel free to post comments to this blog post if you have any questions or comments to Bob or myself or if you find any typos.
So I'll be recording a .NET Rocks! show with Charlie Calvert (my developer community counterpart on the C# team) tomorrow for an (approximate) air date of September 20th. It's my first show so it should be very interesting. :-) Carl and Richard are awesome and two of the funnest people I know in the community so I'm looking forward to it!
I guess people don't realize it, but Charlie and I actually work pretty closely together inside the walls of Microsoft (a.k.a "the office"). We were both in 3 meetings together on Friday with different groups of people, all focused on community in different ways. It's really interesting because before I joined Microsoft I thought there was some huge rivalry between language teams but it turns out not to be the case at all. Charlie and I are working together (with C++ too) in order to drive the best content, relationships and feedback with each of our developer communities.
It should be a fun time tomorrow recording the show -- though I still can't get over listening to my own voice -- it just sounds so weird to me! :-)
I just posted an interview on Channel 9 with John Stallo talking about some cool tools in Visual Studio 2008 that will help you build simple N-Tier applications. Thanks to Kathleen again for helping with the shoot! This time we got fancy and used two camera angles ;-):
Building N-Tier Applications in Visual Studio 2008In this in interview John Stallo, a Program Manager on the Visual Basic Team, talks about WCF and simple N-Tier applications. He talks about a specific architecture scenario and some of the pain points we have building n-tier applications today. He then walks us through the improvements made in the DataSet Designer that physically separates the data access from the structure and validation code and then quickly creates a WCF service and a client that demonstrates this architecture.
You'll probably also want to check out the walk-through John posted here as well if you missed it.
And in case you haven't seen it yet, you can view John's picture and bio along with some of the other team members on the Visual Basic Team page.