Results 1 to 6 of 6

Thread: [RESOLVED] Conversion failed date and/or time?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Resolved [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.

  2. #2
    Registered User
    Join Date
    Sep 2013
    Posts
    4

    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

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    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.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Addicted Member
    Join Date
    Oct 2008
    Location
    Califorina
    Posts
    235

    Re: Conversion failed date and/or time?

    Quote Originally Posted by chdboy View Post
    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());

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Re: Conversion failed date and/or time?

    Quote Originally Posted by smendoza View Post
    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Re: Conversion failed date and/or time?

    Quote Originally Posted by dee-u View Post
    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
  •  



Click Here to Expand Forum to Full Width