Result:
Server Error in '/ZoekSite' Application.
--------------------------------------------------------------------------------
The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The conversion of
a char data type to a datetime data type resulted in an out-of-range
datetime value.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException: The conversion of a char data type to a datetime data type
resulted in an out-of-range datetime value.]
System.Data.SqlClient.SqlDataReader.Read() +176
System.Data.Common.DbDataAdapter.FillLoadDataRow(SchemaMapping
mapping) +175
System.Data.Common.DbDataAdapter.FillFromReader(Object data, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords,
DataColumn parentChapterColumn, Object parentChapterValue) +260
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
+129
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable) +36
ZoekSite.WebForm1.SQLUitvoeren(String orderby) in
D:\Inetpub\ASP\ZoekSite\Zoekpagina.aspx.vb:303
ZoekSite.WebForm1.btnzoeken_Click(Object sender, EventArgs e) in
D:\Inetpub\ASP\ZoekSite\Zoekpagina.aspx.vb:93
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
Göran Andersson said:
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é
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é
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é