System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

After testing out the application i write on the local pc. I deploy it to the webserver to test it out. I get this error. 

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Notes: all pages that have this error either has a repeater or datagrid which load data when page loading.

At first I thought the problem is with the date, but then I can see that some other pages that has datagrid ( that has a date field) work just fine.

anyone having this problem before?? hopefully you guys can help.

Thanks,

0
wijayaer
12/14/2005 11:00:03 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

4 Replies
836 Views

Similar Articles

[PageSpeed] 46

At a guess I'd say your date/time settings differ from your local PC and the Web server.  So your PC might understand that;

30/1/2005

Is a legal date but your web server might be in a different local so sees that as 1st of the 30th month rather than the 30th of the 1st month.

 

The only real solution to this is to tighten up on when you are using date formats and don't just expect .net to always be able to convert a string to a date.

To help resolve this issue debug on both your local PC and the web server to see exactly what data you are trying to convert to date time and see if the one that gives you an error can understand that text as being a valid date time.

0
Aidy
12/14/2005 1:33:31 PM
Aidy's correct, but you should always use ISO date formats when talking to the database that way it won't get confused. If you don't know what these are take a look at the CONVERT function and it should give you a better idea.
0
pkr
12/14/2005 6:42:41 PM

Thank you so much for the Help..but my problem still not solved yet. I still getting that error.

Guys.. here is one of the query having problem on the server. but it works fine on my PC and Laptop.

public System.Data.DataSet getEpExpiryRemind()

{

string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

string queryString = "Select * From EmployeeInfo where EpExpDate >= '" + System.DateTime.Today + "' and EpExpDate <= '" + System.DateTime.Today.AddMonths(2) + "'";

System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

dbCommand.CommandText = queryString;

dbCommand.Connection = dbConnection;

System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();

dataAdapter.SelectCommand = dbCommand;

System.Data.DataSet dataSet = new System.Data.DataSet();

dataAdapter.Fill(dataSet);

return dataSet;

}

0
wijayaer
12/15/2005 10:27:17 AM

Have you read and understood the replies? In what way do you think "System.DateTime.Today" is going to provide the date in the correct format for the database? Also please don't concat SQL strings together it's horrible in so many ways. Take a look at "parameters", which will probably automatically solve your problem anyway, it pays to do things correctly.

 

 

 

 

 

 

0
pkr
12/15/2005 1:41:31 PM
Reply:

Similar Artilces:

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
After clicking my update button I'm receiving this error:    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated. 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. The statement has been...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Hello this is my code: ( I want to see if the date is in a month of a selected year)Dim command As New SqlCommand command.Connection = connection command.CommandType = CommandType.Text command.CommandText = "SELECT count(*) fROM tblRequests r WHERE r.StateID =4 AND r.CategoryID <>2 AND r.CompletionDate BETWEEN '" & year & "-" & teller & "-01' AND '" & year& "-" & teller + 1 & "-01'"Dim objaantal As Object = command.ExecuteScalar() Dim Incidents As Integer If Not objaantal Is No...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
  Hi , i m inserting the values in the fallowing ways INSERT INTO LoginHistory([UserID],[LoginTime],[LoginIP])VALUES('NilCom1Ad01','13-04-2009 4:52:54 PM','127.0.0.1' ) Still i  m Geting errror  The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated.Plz  help me  I'm wondering if your database is expecting month/day/year, in which case 13 would be causing your problem.  Change the date to 04-13-2009 and give it a try.C# <---> V...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Hey, I have a big problem that i wanna search data from SQL by DateTime like thatselect * from test where recorddate='MyVariableWhichHoldDate'i use variable that holds Date info.i searched a lot infomation on net but there is no perfect solution. i know why this occur but there is no function to solve this problem. i used a lot of ways. it accept yyyy-mm-dd format but my variable format is dd-mm-yyyyy . is there any function for this problem? and any other solution.thanks for ur attentionregards Just do select * from table where dateField = '1-1-2005'. This will work..Nick The safest for...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
 Please help me its give me the error on server but run successfully on my local  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...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-b...

conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
  When I run this error I get this error  ' The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.' select distinct pro.prodname, pro.price, pro.description, pro.fromdate, pro.todate, pro.pic1 from products pro inner join booking on pro.category=booking.category where pro.category=1 and '12/11/2008' between pro.fromdate and pro.todate and '18/12/2008' between pro.fromdate and pro.todate and '12/11/2008' not between booking.checkin and booking.checkout and '18/12/2008' not between booking.chec...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
 Hello,When i run my project in VS IDE i dont get this below mentioned error but assoon as i put it in IIS of my server machine i get this error.I am using this application since months and wasn't getting any error. But recently when my admin made some changes in server..This error started coming. I have no help from my admin regarding this.  Let me know if i have to do some changes in c# code or in database or in windows server machine or in IIS or in crystal report properties !! The error is as follows : Normal 0 false false false ...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
I still don't know what is happening with my application. I used before in another page the formview control and I didn't have the out of range Date error. It was normally. But now, I'm doing everything manually and I don't know why, but I'm with this problem. I need to safe this problem today... Here go my code!Thanks Raphael <%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SQLClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> ...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. #3
 I use the ajax calendar to select date. When I add the selecting date, I convert it to string. in my database the field is varchar to add this date. However when I add some date I take this warning The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. I can not understan this situation :S Hi! Can you please tell  at what point of time you are getting this error? whether at the time of converting the selected date into string  or while saving in the DB. As you mentioned, the database field is varchar , then there is no cha...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. #2
sombedoy can solve this problem:   my code:   '######################################## '# Create values for XML File # '########################################Dim command As New SqlCommand command.Connection = connection command.CommandType = CommandType.Text  Dim datum1, datum2 As DateTime   datum1 = teller6.ToString & "/01/" & jaar & " 0:00:00" datum2 = (teller6 + 1).ToString & "/01/" & jaar & " 0:00:00"   command.CommandText = "SELECT count(*) fROM tblRequests r WHER...

Error : The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
 My website is facing one problem after hosting to the server.When i execute my code from local(india) all working fine.But when i host it to UK,the error coming "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value" . I used Culture=en-GB in web.config.But not solved.This error is coming to all pages where datetime value is using..Please help me ..  Can you post your code or screenshot showing the error on some code line...  Thanks,santosh_maharajaPlease mark as answer if you got expected solution.  this is ...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. #2
I still don't know what is happening with my application. I used before in another page the formview control and I didn't have the out of range Date error. It was normally. But now, I'm doing everything manually and I don't know why, but I'm with this problem. I need to safe this problem today... Here go my code!Thanks Raphael <%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SQLClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> ...

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. #2
Advance thanks ....... My table is  TimeSheet:-----------------------------------  CREATE TABLE [dbo].[TimeSheet](    [autoid] [int] IDENTITY(1,1) NOT NULL,    [UserId] [int] NOT NULL,    [starttime] [datetime] NOT NULL,    [endtime] [datetime] NOT NULL,    [summary] [nvarchar](50) NOT NULL,    [description] [nvarchar](50) NULL,    [dtOfEntry] [datetime] NOT NULL,    [Cancelled] [bit] NULL) ON [PRIMARY] My Query is------------------ insert into tim...

Web resources about - System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. - asp.net.sql-datasource

Resources last updated: 11/29/2015 12:16:08 AM