Saturday, January 28, 2006

No Help at All

When working with ADO.NET, I have fantasies. One of my favorites is an encounter between William Gates and the Washington State Police:

Gates: Hi, officer, what's the problem?

Officer: May I see your licence and registration please, sir?

Gates: Yes, here they are.

Officer: Do you know why I stopped you?

Gates: Well, no, really, I might have been going a little fast.

Officer: We'll get to that.

(pause)

Officer: Mr. Gates, I'm going to cite you for the following: Failed to meet all legal requirements. One or more of the subsystems of your automobile violated one or more of the laws of the State of Washington. For more information, see the Washington State Vehicle Code.

Gates: But what's wrong with my car?

Officer: Please refer to the Washington State Statutes for further information. You'll be talking to the judge about the details. Have a nice day, sir.

This is what Mr. Gates told me about my error:

"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

As far as I can see, all constraints are being met, so this is the error message I would prefer:

"Failed to enable constraint Parent_Child. The child row has a foreign key of 1012, but no row in the parent table has a primary key of 1012."

I fantasize about Bill Gates pacing around his car trying to decide if a tail light is out or there's a crack in his windshield or maybe the muffler is a little loud. But he can't quite tell because none of them seems to be out of limits. And maybe it's none of those things. He has to get a copy of the vehicle code and read it from cover to cover to figure out why he got a ticket. Seat belt? Tire pressure? Damn, that cop could have given him a hint.

Wednesday, January 11, 2006

Copy Screen

.NET 2.0 has so many new features that I'm still excited every time I open the MSDN document viewer. The one I just found is copying a chunk of the screen into a bitmap. If your application support procedure includes instructing the struggling user to select your window and press Alt+PrntScrn, and then open Paint, and then press Ctrl+V, and then... blah, blah; now you can do that all programmatically. The new function is Graphics.CopyFromScreen. There is a short sample on my web site.

Tuesday, January 10, 2006

Fie on Data Binding

Data binding sounds so useful when you read about it at a high level, but the details are not up to the promises. Here is a very short, succinct example:



  1. Prepare your data source as a BindingList(Of type) or a DataTable.

  2. Drag and drop a tool strip onto a form and add a ToolStripComboBox to it to display your data in.

  3. Assign the data source to the DataSource member of the ToolStripComboBox.


There, you're done. Easy, wasn't it?


Well, that's what you would assume you do by reading the high-level documentation (i.e. hype). The fact is, a ToolStripComboBox does not have a DataSource member.

Sunday, January 08, 2006

Data Binding

I've been playing with the new data binding classes in VS2005. Clearly, a lot of time and effort went into these. I'm looking forward to some books to come out to explain what they are.

In the meantime, I put together a little demo program to illustrate one tiny particle of one small corner of data binding: binding a data grid view to a list of "business objects." It's really easy to do, but it took me literally hours to figure out how to do it. We need books. You publishers are falling behind.

Take a look at the demo and comment. Comments by non-members are now enabled.

Sunday, January 01, 2006

What Good Is That?

VS2005 has code refactoring. There are several refactorings you can do, from a simple rename to extracting a method. I love extracting a method. I hate rename. Let me explain.

When I'm first writing a method, I tend to name local variables with short, cryptic names because they're easier to type. After I get the bulk of the method written, I want to change the names to something more meaningful. In VS2003 I would select the body of the method and do a change all in selection. Worked just fine.

In VS2005, I thought the Refactor, Rename would be a better way to go. So I would select that p or whatever and rename it. The problem is that Refactor, Rename is even stupider than a text replacement command. It wants to change every p in the entire solution. Why would it do that? Clearly, it knows this p is a local variable and is in no way related to any other p anywhere. But it insists on putting up a tree with every p in the program. Then I have to uncheck all the ones I don't want to change. What good is that? It's easy to make a mistake and change something you don't want to. At least with the Change Text command, it limits itself to the selection.

Stupid, stupid, stupid.