Hello guys,
I have my problem in saving date to mysql.
Dim conn As MySqlConnection
Dim myCommand As New MySqlCommand
Dim commandB As MySqlCommandBuilder
Dim data As MySqlDataAdapter
Dim query As String = "SELECT * FROM events e;"
Dim myconnstring As String
Dim comm As String
Dim vers As String = TBox.Text & " " & "VS" & " " & tBox2.Text
Dim eventdate As String = Format(DateTimePicker1.Value, "yyyy-dd-MM HH:mm:ss")
myconnstring = "datasource=localhost;username=root;password=*******;database=*******;"
comm = "INSERT INTO `newscoring`.`events` (`gametype`, `date`, `vs`, `aa`, `aaa`, `aaaaa`) VALUES ('sample', '" & eventdate & "', '" & vers & "', '" & RBox.Text & "', '" & UBox.Text & "', '" & pbox.Text & "');"
conn = New MySqlConnection(myconnstring)
Try
conn.Open()
Try
data = New MySqlDataAdapter(query, conn)
commandB = New MySqlCommandBuilder(data)
Dim res As New MySqlParameter
res.Value = commandB
myCommand.CommandText = comm
myCommand.Connection = conn
myCommand.ExecuteNonQuery()
Catch myerror As MySqlException
TTimer.Stop() : Sclock.Stop()
MessageBox.Show("Saving event error: " & myerror.Message)
conn.Dispose()
End Try
Catch myerror As MySqlException
TTimer.Stop() : Sclock.Stop()
MessageBox.Show("Saving event error: " & myerror.Message)
conn.Dispose()
End Try
conn.Dispose()
Error message:
Error 1292: Incorrect datetime value: '1-1-2013' for column 'date' at row 1
In this line the value were get.Dim eventdate As String = Format(DateTimePicker1.Value, "yyyy-dd-MM HH:mm:ss")