-
Sep 17th, 2013, 10:57 PM
#1
Thread Starter
Lively Member
[RESOLVED] Conversion failed date and/or time?
I want to insert date to the column Date of birth
Code:
"insert into table (firstname,lastname,dateofbirth) values(?,?,?)"
Code:
statement.setString(3,dob.getText());
dob is my JTextField name
Data type of that column is Datetime2
I have inserted two records ,but when I tried to insert another record it gives me error
Code:
Conversion failed when converting date and/or time from character string.
Last edited by chdboy; Sep 17th, 2013 at 11:38 PM.
-
Sep 18th, 2013, 02:19 AM
#2
Registered User
Re: Conversion failed date and/or time?
'Upd.Open "Insert into Table (Firstname,LastName,dateofbirth) " _
'& " Values ( 'Antony','Chinnappa','" & Format(Date, "dd-mmm-yyyy") & "')", Connectionstring,1,3
-
Sep 18th, 2013, 02:59 AM
#3
Re: Conversion failed date and/or time?
Do you mean to say you were able to save 2 records using the same code? If yes then probably what you have inputted in the 3rd record is not a valid date/time.
-
Sep 20th, 2013, 06:43 PM
#4
Addicted Member
Re: Conversion failed date and/or time?
Originally Posted by chdboy
I want to insert date to the column Date of birth
Code:
"insert into table (firstname,lastname,dateofbirth) values(?,?,?)"
Code:
statement.setString(3,dob.getText());
dob is my JTextField name
Data type of that column is Datetime2
I have inserted two records ,but when I tried to insert another record it gives me error
Code:
Conversion failed when converting date and/or time from character string.
I'm assuming the dateOfBirth column is of the dataype of DATE, you're telling it set as the dob column as string try this.
Code:
statement.setDate(3,dob.getText());
-
Sep 22nd, 2013, 08:29 AM
#5
Thread Starter
Lively Member
Re: Conversion failed date and/or time?
Originally Posted by smendoza
I'm assuming the dateOfBirth column is of the dataype of DATE, you're telling it set as the dob column as string try this.
Code:
statement.setDate(3,dob.getText());
I'm saving the data into database not to get text
-
Sep 23rd, 2013, 12:28 AM
#6
Thread Starter
Lively Member
Re: Conversion failed date and/or time?
Originally Posted by dee-u
Do you mean to say you were able to save 2 records using the same code? If yes then probably what you have inputted in the 3rd record is not a valid date/time.
Yes,I looked closely then I found out that the two records which has date ,was in format "yyyy/mm/dd" and the third input I was trying with "dd/mm/yyyy" format ,that was the problem.
Now my another question is how Do I set my JTextField to put date format like "dd/mm/yyyy"?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|