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!

inserting date string into a smalldatetime

Status
Not open for further replies.

jesse1

Programmer
Aug 29, 2008
30
US
One of the fields in a csv file is date of birth. The dates is retrieved correctly but Iget the followng error when trying to insert it,

Error: Macromedia][SQLServer JDBC Driver][SQLServer]Conversion failed when converting character string to smalldatetime data type.


Code:
INSERT INTO player(sfirst,slast, dob, position,idnum, school,district, coach) VALUES ( (param 1) , (param 2) , '1/1/1997 ', (param 3) , (param 4) , 17, 6, 0 )

 
Knowing the value of the date and the code you use to generate the sql would be helpful.

Vegans are friends, not food...
 
It's my guess (which I can only do based on the lack of code) that one or more of your dates are not valid ones. As you loop over the data in your CSV file, output the date field to the screen before each database insert. As soon as you hit an invalid date, you'll get an error and see the offending date printed before the error.

Of course you can use other debugging techniques. One I've employed is built right into an import mechanism I wrote where data in a CSV file might be invalid. Basically loop over the CSV and build a report for yourself for each bad date, then dump it to the screen so you can examine it. In the case of the project I just mentioned, I programmatically create a report that the user receives with a list of invalid records, which are skipped over. Valid records are written to the database.

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top