Monday 21 July 2008

System.Web.Query.Dynamic.ParseException: Digit expected

Today I wrote a quick piece of code using Linq to Sql that would pull out some records from a table given a provided where clause
To make my life easy, I used a LinqDataSource within a web form and then databound a form view to it, this was only a quick prototype of an idea so I felt these were appropriate.


The where clause for my LinqDataSource was being assigned programatically and consisted of a GUID value from a user object I had knocked together. Upon compiling and running the code though I got an odd error: System.Web.Query.Dynamic.ParseException: Digit expected


First thing to check was that the value I was giving the where clause was actually an GUID value, debugging showed this fine, I next looked at putting a hard coded GUID where clause in to see if it was some weirdness caused by my user object, but this wasn't the case. I finally googled the error message, and found 1 meesly result which pointed to the MSDN forums.


Here someone posted that you can convert to various types and to try explicitly converting to a GUID value


   lds.Where = string.Format("user_id == Guid({0})", user_id);

This worked fine, and it made sense too, as when you declare where parameters on the linqdatasource control you normally define its type, as I wasn't doing this nor programtically it was type casting by itself.

No comments: