Richard Howells' Blog
Author: RichardHowells Created: 11 March 2008
Notes about the interesting (my definition) bits I discover in my programming. Plus, of course, the occasional tar pit.

A – Because the browser does not work the way you think it should.  When you press F5 the browser requests the resource it is currently on AND resources directly linked to that page – images.  I set up a web site to serve images with an expiry time.  The idea is that most of the graphics in the skin change rarely.  The browser does not need to down load a fresh copy for each request.

Fired up fiddler, pressed F5 a few times and got stumped.  Every time the browser was making a fresh request for each image.  When I moved to requesting the page via a link, even a link on the same page, I saw the cache work as I expected and the requests vanished.


 Add this (or similar) to the URL

"?SkinSrc=Portals/_default/Skins/MinimalExtropy/index full"

I posted this so that I would be able to find it easily for myself.  You can do somthing similar with ContainerSrc too.

Shows how to create a set of hierarchical check boxes.  Checking/unchecking a box at the higher level automatically checks/unchecks the ones at the next level down.

Read More »

I wanted a very simple logging table. I wanted it to be time ordered and I decided to include a smalldatetime column in the primary key.

This failed badly with Entity Framework. Inserts resulted in a failure message indicating that zero rows were affected. This because a .Net DateTime value is not guaranteed to round trip into SqlServer and back. The SqlServer datetime (and smalldatetime) column types cannot store values with the same precision as the .Net DateTime type.

EF uses a query like this [1] to store the row and recover the freshly inserted identity column. The DateTime value is ‘rounded’ to suit SQL Server as it is inserted and the Select fails to read the freshly inserted row back because the datetime values are no longer equal.

I solved this by removing the datetime column from the primary key. It was not crucial for it to be in the primary key.

Moral – do not mix datetime and identity columns in your primary key.

[1] Entity Framework Generated Query exec sp_executesql...
Read More »

 You need all these MIME types.  Most of them are probably inherited from higher up but I needed to add a couple - could have been a version thing!


I found this StackOverflow question useful

 If you came on the 327 course (C++) I taught at Learning Tree week of 16Feb and have been waiting for your follow up email please accept my apologies.

Somehow I lost the pile of papers with your email addresses and I have no way of contacting any of you.  Send me an email address and I'll send you the promised material.

Just one way a 30 minutes job can take 5 hours.

Read More »

DataGridView – how to show a subset in a DropDownColumn

The standard approach is to add event handlers for CellBeginEdit and CellEndEdit. In CellBeginEdit a new datasources is bound to the dropdown and in CellEndEdit the binding is reversed. Here is a sample from the DataGridVew FAQ.

private void dataGridView1_CellBeginEdit(object sender,         DataGridViewCellCancelEventArgs e)


if (e.ColumnIndex == territoryComboBoxColumn.Index)


// Set the combobox cell datasource to the filtered BindingSource

DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1                        [e.ColumnIndex, e.RowIndex];

dgcb.DataSource = filteredTerritoriesBS;


// Filter the BindingSource based upon the region selected

this.filteredTerritoriesBS.Filter = "RegionID = " +

this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();




Read More »

I've been working with a group who inherited some bad code when the software house supplying them went bust.  When the application added or updated data in SQL Server sometimes date values were accepted in US format and sometimes in UK format.  On the Test server it was one way and on the Live it was the other.

It's never good when live and test have different configurations but applications often need to work properly regardless of details like date format configurations.  The solution is to use parameters properly.  I wrote about it here.

I just wrote about using a generic extension method as an alternative casting syntax.  I've been using it in some code I've been working on.  I like it.

Find it in the Forum (click here)

Copyright 2002-15 by Dynamisys Ltd