Datetime can't insert into MYSQL table by VB net 2K8 Express RRS feed

  • Question

  •     Dim sToday As String = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
        InsertToTable(sToday, "999", "Testing by service", "0")
        Public Sub InsertToTable(ByVal _smsdate As String, ByVal _smsfrom As String, ByVal _smscontent As String, ByVal _smsstatus As Char)
            Dim myConnectionString As String = "Database=sata;Data Source=localhost;User Id=root;Password="
            Dim conn As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
            Dim myInsertQuery As String = String.Format("Insert Into SMSinbox (smsdate, smsfrom, smscontent) values ('" & _smsdate & "', '" & _smsfrom & "', '" & _smscontent & "')")
            Dim cmd As New MySql.Data.MySqlClient.MySqlCommand(myInsertQuery)
            cmd.Connection = conn
        End Sub
    field type: smsdate on table: smsinbox is datetime, any suggestion? pls help, thanks.
    • Moved by VMazur Tuesday, June 14, 2011 11:03 AM (From:ADO.NET DataSet)
    Sunday, May 22, 2011 10:12 AM


All replies

  • Hello andibach,

    Thanks for your post.

    According to your description, I think you could try to replace your datetime parameter to CURDATE(), which returns the DATE part of the current time. Manual on CURDATE().

     It is always worth to taking a look in the manual first. Date and time functions in the mySQL manual

    I hope this can help you, if you have any questions, please feel free to let me know.


    Have a nice day,

    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jackie-Sun Tuesday, May 31, 2011 4:37 AM
    Tuesday, May 24, 2011 6:09 AM
  • Hi Jackie,

    thanks for your help. It's very helpful.

    I let you know that I've removed my scripts above into my windows service (not in windows app)  It works! but not working on windows app project.


    Thursday, May 26, 2011 3:00 PM