Re: Dates



That doesn't matter. The SQL query is a string, so the date in it is a part of the string, not a separate DateTime value.

Frederik Vanderhaeghe wrote:
But in my SQL Server the field is of the type 'Datetime'

Fré
"Göran Andersson" <guffa@xxxxxxxxx> wrote in message news:e3xQBL2bGHA.4900@xxxxxxxxxxxxxxxxxxxxxxx
You are implicitly converting the date to a string, that means that it's using the culture settings of the current thread. You should specifically convert the date to a string, and specify how it should be converted. You can use a CultureInfo object, a DateTimeFormat object or a specific format string.

I suggest that you use the ISO 8601 date format. It's unambigous, contrary to the dd/MM/yyyy and MM/dd/yyyy formats, that will depend on the culture settings of the database server.

...
where datum = '" + kalender.SelectedDate.ToString("yyyy-MM-dd") + "'
...

Frederik Vanderhaeghe wrote:
I actually use the calendar object of asp.net. So the select is:
select *
from TBL_Bestanden_Zoeken
where datum = '" & kalender.SelectedDate & "'

But when I search in the SQL Server itself, I can't do this:
select *
from TBL_Bestanden_Zoeken
where datum = '31/12/2005'

The result of kalender.SelectedDate is '31/12/2005'. But when I search for datum = '2005/12/31' it works, but only on the SQL Server, not when I hardcode it in ASP.Net.

It's a very weird thing

Fré

"Göran Andersson" <guffa@xxxxxxxxx> wrote in message news:udW9Zx1bGHA.3908@xxxxxxxxxxxxxxxxxxxxxxx
Do you just send the date as a string to the database, or is it converted to a DateTime at any stage?

Frederik Vanderhaeghe wrote:
Hi,

I have made a search page on which users can search for documents. They can search by documentnumber, customername,... and also by date. Now the problem is that when a date is entered it doesn't show anything.

When I look at the SQL server Enterprise management and make a query there, the following works:
select *
from TBL_Bestanden_Zoeken
where (datum='2005-12-31')

When I code it like that in my asp.net site, that when the field is not empty, it searches for the documents with date='2005-12-31' then it doesn't give any results.

What can I do?

Fré

.



Relevant Pages

  • Re: Failed to convert parameter value from a String to a DateTime
    ... perhaps the error occurs because SQL Server defaults to nvarchar when a parameter is NULL. ... I would try to declare the parameter as DateTime before to assign it the DBNull.Value. ... value may be a valid date such as '01/01/2007' or a null string. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Variable as Alias Name
    ... @friday_as_of_date must be a string in order to concatenate the value with the remainder of the SQL string. ... I suggest you use sp_executesql sp that you can pass @org_level_1_name as a parameter instead of building the value into the SQL statement itself. ... Conversion failed when converting datetime from character string. ... declare @sqlstring varchar ...
    (microsoft.public.sqlserver.programming)
  • Re: BETWEEN in dynamic SQL
    ... I have a mess in printed SQL. ... > Instead of EXEC sp_executesql @sql ... >> Syntax error converting datetime from character string. ...
    (microsoft.public.sqlserver.programming)
  • the safest way of handling datetime between asp.net and ms sql
    ... I know that a problem of different datetime strings formatting between ... asp.net and ms sql has been covered here widely, ... Let's say I'm keeping datetime variable in a session. ... cast it - how can I prevent it from casting it to string and inserting ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Dates
    ... Do you just send the date as a string to the database, or is it converted to a DateTime at any stage? ... Frederik Vanderhaeghe wrote: ...
    (microsoft.public.dotnet.framework.aspnet)

Loading