The following code assigns DateTime.MaxValue to a parameter. When trying to run this code against the Northwind databse, it will produce the error, "An overflow occurred while converting to datetime".
SqlCeConnection conn = new SqlCeConnection(connStr); conn.Open(); SqlCeCommand cmd = new SqlCeCommand("select * from employees where [Hire Date] < @paramDate", conn); SqlCeParameter paramDate = cmd.CreateParameter(); paramDate.ParameterName = "@paramDate"; paramDate.DbType = DbType.DateTime; paramDate.Value = DateTime.MaxValue; cmd.Parameters.Add(paramDate); SqlCeDataAdapter da = new SqlCeDataAdapter(cmd); DataTable tbl = new DataTable(); da.Fill(tbl); dataGridView1.DataSource = tbl; conn.Close();
Note that this fails when using MSSQL Compact Edition (MSSQLCE) under a standard WinForm application and a Pocket PPC platform. The same code against a standard desktop MSSQL version will work fine.
The workaround is simple. Just get away from the MaxValue. Of course, this is a workaround, so it's not perfect, but it certainly works for my needs.
paramDate.Value = DateTime.MaxValue.AddMilliseconds(-1);
Sorry for the changing plans, but I just received word that CodeGear won't be able to make it out here for the 2/27 meeting so the DUG meeting will be cancelled. They may be able to reschedule in April, so that will give us some more lead time, but for now, things are off. Thanks for your understanding.
I was banging through some quick and dirty sample applications today, in preparation for a talk on LINQ tonight. One of my old LINQ to SQL demos shows how to use the external xml mapping file. I also blogged about this before. Today, I kept getting the following error whenever I would run with an external xml mapping file: The type 'Order' is not an entity.
I was using the following command line to generate the xml mapping file:
SqlMetal /server:(local) /database:Northwind /map:Northwind.xml /code:Northwind.cs /pluralize
Looking at the resulting xml file, I finally noticed this section:
<Table Name="Orders">
<Type Name=".Order">
Notice the leading dot before the type name attribute. That's the problem. So I went back and added the /namespace switch to the sqlMetal command line, and now all is well with the world again. Granted, this problem is the result of me doing demo work, and not production work, but it's still a little bit irritating. Then again, I'm still running the May 2006 CTP on VS2005, so for all I know, MS has already fixed all of this with a subsequent release of a build in Orcas.
I just received an email from Anders Ohlsson, and he wants to schedule Milwaukee as a stop on a 10-city tour. I take that as a positive sign that Milwaukee matters enough to warrant a stop. Let's keep that perception alive by coming out and attending this meeting! The very tentative details right now are:
- What: Delphi User Group Meeting
- When: Tuesday, 2/27/07 from 7pm-9pm.
- Where: Medical College of Wisconsin
- Why: Because you want to hear about updates on CodeGear, the roadmap and Delphi itself. CodeGear would also provide door prizes and a rebate offer.
- How: RSVP by emailing me.
If you have any other thoughts, concerns, questions, etc., send me an email. I will post final details once we have them.
I had a requirement to make a list of objects be displayed in some kind of a grid metaphor. I've used the DataGridView before, and even written some blog entries on extending it (check out the cool Search feature on my blog for more information). However, all of my grid usage had been limited to database-related use.
What I needed was a way to easily get filtering and sorting working for the list of objects. I found 2 links that helped me out a ton. The first one is Building a Drop-Down Filter List for a DataGridView Column Header Cell. This article is incredibly well-written and talks about the different interfaces you need to implement, and provides a sample, too. For the sorting, I used Brian Noyes' BindingListView class from Chapter 9 of his excellent book, Data Binding with Windows Forms 2.0.
When stitching these 2 pieces together, I noticed several things:
By doing all of this, I got things working the way I wanted. Now it's time to tackle the next task of getting child objects bound properly in a DataGridView.
I came across EViL last week when looking into simplifying validation of domain objects. This open-source project is done very well. Dave Donaldson introduced EViL last month.
In a nutshell, it's a library that provides attribute-based enforcement of business rules on your entity objects. It comes with a bunch of pre-defined attributes to handle common scenarios (e.g. a field is required, a field should have a maximum length, a field should match a certain regex, etc.). It also easily allows for adding new, custom rules.
The thing I like best about this project is that it doesn't force you into descending your classes from some super class. You can do that if you want, but it will also work if you want to leave your classes alone. All in all, I would highly recommend looking into using EViL in your .NET applications.
Well, I suppose this is proof of the power of this meme since it even reached me (from Hallvard). Some of these may be better known than others, but at least they're off the beaten, technical path.
- I started my college career as a performance music major playing the trumpet. While I love music to this day, I realized early on that I didn't want to be a teacher, and I always had a knack for computers, so I switched away from music.
- I played football for the UW-Madison Badgers in 1988. Well, "played" may be an exaggeration. I walked on under the Don Morton era and made the team as a free safety. By the spring game, I received a subluxation of the shoulder after a nasty collision. While rehabbing, I reinjured the shoulder and finally hung it up.
- I started computer programming in ninth grade on a TRS-80, Model I. I tested out of math, so that's what they had me do instead. They eventually allowed me access to the faculty Apple ][, and I ended up teaching a bunch of faculty members how to program it. I even got my picture in the local paper for that.
- My obsession for all things Apple lasted through college. I was a student Macintosh expert at the MACC (now known as DoIT). That's how I also got into Pascal, using TurboPascal for Mac, Lightspeed Pascal, and Macintosh Programmer's Workshop. I took my first professional job out of college working in DOS, and sadly, have never returned back to the Mac.
- I have always wanted to work for the NSA. However, I can't ever imagine living on the east coast (how's that to slight an entire third of the nation!
). Maybe after the kids go to college, I'll see what kind of opportunities exist.
To pass it on, I'll tag Steve Trefethen, Rich Werning, Mark Edington, Geoff Lane, and fellow Badger alum Chris Peterson.
|