Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Data.SqlClient.SqlException: The conversion of a char data...

Status
Not open for further replies.

auchtum

Programmer
Nov 21, 2008
20
US
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 terminated.

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 (0x80131904): 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.]System.Data.SqlClient.SqlConnection.OnError(SqlException
exception, Boolean breakConnection) +925466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,
Boolean breakConnection) +800118
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +186 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,
Boolean async) +196
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +269
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
ASP.propuesta_p2_aspx.Page_Load(Object obj, EventArgs e) +806
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +33 System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +1436



I noticed when I run it from my machine to the customer's server it works
fine (I guess is because i have installed VS 2005 there) but at customer's pc
machines don't work. How can i fix this?

 
looking through the stack trace, it appears you are using a sqldatasource. the trace jumps from page_load to executenonquery. if that's the case then your problem cannot be debugged easily because you cannot unit test markup and you cannot debug markup code.

the error is having problems converting a string/char to a datetime object. if the data is stored as a string that's a problem. it should be stored as a date. if the value passed to the command is a string that's a problem. it should be passed as a datetime object to a sql parameter.

there is one final issue it could be, although the error message is somewhat decieving if this is the case. the DateTime.Min or default(DateTime) and DateTime.Max value is out of range for SqlServer. there are conversion functions on the web about how to covert
.net DateTime.Min to sql server datetime default values and vice versa.

once you fix this issue I would highly recommend moving away from datasource controls and instead wiring the objects in the code behind. This will at least enable you step through the code using the debugger to see where it's breaking.

taking this one step further you could implement an MVP for the webform's codebehind thus decoupling the presentation from the logic, which will allow for unit testing.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
As I have iterated in your last 2 posts, STOP using the datasource controls, you cannot debug them!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top