Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
PROBLEM WITH DATE CONVERSION
PROBLEM WITH DATE CONVERSION
Rate Topic
Display Mode
Topic Options
Author
Message
lonhanner
lonhanner
Posted Thursday, December 27, 2012 11:51 AM
SSC Rookie
Group: General Forum Members
Last Login: Friday, February 22, 2013 11:14 AM
Points: 39,
Visits: 141
I have a column called "UP_DATE". When the code below trys to read "UP_DATE" I get the following
riders.UP_DATE = CDate(reader("UP_DATE").ToString)
error. Conversion from string "" to type date is not valid. It looks as its tring to convert time. here is the data I get. riders.UP_DATE #12:00:00 AM#. Anyone have a solution to how to fix this column
.
When i query the data in SQL server manegement it displays the date fine. I have other date fields and they convert ok.
Post #1400722
Sean Lange
Sean Lange
Posted Thursday, December 27, 2012 12:34 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 2:33 PM
Points: 8,620,
Visits: 8,261
lonhanner (12/27/2012)
I have a column called "UP_DATE". When the code below trys to read "UP_DATE" I get the following
riders.UP_DATE = CDate(reader("UP_DATE").ToString)
error. Conversion from string "" to type date is not valid. It looks as its tring to convert time. here is the data I get. riders.UP_DATE #12:00:00 AM#. Anyone have a solution to how to fix this column
.
When i query the data in SQL server manegement it displays the date fine. I have other date fields and they convert ok.
What is this code and what does #12:00:00 AM# mean? That looks like data from Access or something.
The error message is however pretty self explanatory. Whatever is reading your table it is getting an empty string in reader("UP_DATE") which can't be cast to a datetime object in many languages. t-sql will convert an empty string to 1/1/1900 but .NET will throw an exception when parsing a date from an empty string.
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1400725
lonhanner
lonhanner
Posted Thursday, December 27, 2012 12:54 PM
SSC Rookie
Group: General Forum Members
Last Login: Friday, February 22, 2013 11:14 AM
Points: 39,
Visits: 141
Yes the data came from ACCESS. I imported to sql. Is their anyway I can convert the "UP_DATE" Column to the sql date type. If so could you give me an example query to do this.
Thanks
Lon
Post #1400729
Sean Lange
Sean Lange
Posted Thursday, December 27, 2012 1:24 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 2:33 PM
Points: 8,620,
Visits: 8,261
lonhanner (12/27/2012)
Yes the data came from ACCESS. I imported to sql. Is their anyway I can convert the "UP_DATE" Column to the sql date type. If so could you give me an example query to do this.
Thanks
Lon
Not sure what datatype it is now or if everything in it will convert correctly but...
alter table MyTable
alter column MyColumn datetime
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1400733
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.