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.

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)

A year ago I decided to try the delights of developing as a non-admin.  It’s been great, I didn’t regret it.

My machine has been showing the symptoms of software rot.  Yesterday evening I repaved my machine.  I organize my disk as a partition for the O/S plus software and a separate partition for data.  I did a total ground-zero reinstall of the O/S (Win XP Pro), on a freshly formatted partition.  One effect of that is that my new account has a new SID.  All the old files on my data partition allow me to read them – I’m a User, but they don’t let me delete/write/update because my new SID is different to the one they were created with.

I think I am going to have to live with manually changing file permission settings for many months to come – I’d be *very* interested to hear of any cute shortcuts to that process.  More important – I’m expecting to have to re-pave again, annually seems about normal for me.  What I'd really like is some ideas on what I can do to stop this problem next time?

Read More »

Got a text about a parcel?  Ignore it!

Read More »

I'm working in Edinburgh this week and it's the Edinburgh Festival time. Definitely .

Laura is up here too, ready for next term.  We were planning to go to see Paul Merton's improvisation show, but we only had one ticket.  I'd got the last one when tried to book for both of us.  We hoped we might be able to get a press return.

We couldn’t get a press ticket at the box office, she tried calling in a favour from someone who was working in the venue, but no joy.  So I was just keeping her company in the queue.  A venue worker went past collecting ticket stubs – “I’m just standing here – couldn’t get a ticket.”  Five minutes later she was back – "There’s a guy farther back in the queue with a spare ticket."  He sold it me for a tenner but I'd have given him £15. Whoo-hoo.  I don’t think Laura stopped laughing for a whole hour – it was *that* good.  I'd seen them before, but hey - it's improvisation. ...
Read More »

Copyright 2002-15 by Dynamisys Ltd