locked
got error when i try to insert datetime to MySQL RRS feed

  • Question

  • hi

    i try to insert datetime val to MySql and got error

    Tdate is datetime in MySQL

    in C# WinForm i insert like this:

    insert into MyTable (id,Tdate) value ('2','" + Convert.ToDateTime(_AllDate)  + "')";

    how to do it ?

    • Moved by Barry Wang Wednesday, January 22, 2014 11:13 AM
    Tuesday, January 21, 2014 6:57 PM

All replies

  • ..." + Convert.ToDateTime(_AllDate)  + "')" is the same as ..." + Convert.ToDateTime(_AllDate).ToString()  + "')". And the result Convert.ToDateTime(_AllDate).ToString() depend on the date and time formats setting on your computer, it may provide the wrong date string for MySQL query, so,please change from 

    Convert.ToDateTime(_AllDate)

    To

    Convert.ToDateTime(_AllDate).ToString("yyyy-MM-dd HH:mm:ss")

    Wednesday, January 22, 2014 4:17 AM
  • This forum is for the desktop user interface Windows Forms.

    You should not insert data handling in a User Interface, but in a data class or in a data layer.

    Be aware MySQL is not a product from Microsoft which has at least 2 freeware better solutions.

    Your question is 100% off topic, but there is simply no MySQL forum on MSDN search on Google for it or use a Microsoft product.


    Success
    Cor

    Wednesday, January 22, 2014 10:50 AM
  • Hi E_gold,

    The following forum will be more appropriate:

    http://forums.mysql.com/

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 22, 2014 11:13 AM