Search code examples
c#asp.netsql-server-2008culture

asp.net Culture causes error when reading date datatypes from sql


What I was trying to accomplish is change the language on the asp.net calendar control and from what I read I can use:

<%@ Page Title="" Culture="es-PE"....

But when I do this I get the following error:

Conversion failed when converting date and/or time from character string.

My database collation is

SQL_Latin1_General_CP1_CI_AS

Never had to do this before so this is new to me. It needs to be a spanish page so if I show "December" they won't have a clue what month is displaying..and no I can't ask them to take English classes lol..

Thanks in advance..


Solution

  • You should NOT send a string to SQL Server to start with. You should parse the string into a DateTime variable and submit this variable to the SQL side using a parameter. This totally avoids the issue of SLQ Server not knowing your locale on the page.

    THAT SAID: never se the culture in the page, put it at least in web.config so you can deal with site wide changes from one place, not from dozen or hundreds of individul pages.