Wednesday, April 21, 2021

[VB.Net][stored procedure] vb date type to mysql datetime format

Source:

Dim dbCommand As New MySqlCommand

With dbCommand

  .Connection = gConn

  .CommandText = "SP_TEST"

  .Parameters.Clears()

  .Parameters.AddWithValue("?IN_DATE",paper.pubDate) 'Where paper.pubDate is type "Date"

  .Parameters.Add("?OUT_RESULT",MySqlDbType.Int16.).Direction = ParamterDirection.Output

  .CommandType = CommandType.StoredParameter

End With


Correction: Using toString() function to out the date to mysql datetime format string.

Dim dbCommand As New MySqlCommand

With dbCommand

  .Connection = gConn

  .CommandText = "SP_TEST"

  .Parameters.Clears()

  .Parameters.AddWithValue("?IN_DATE",paper.pubDate.toString("yyyy-MM-dd HH:mm:ss"))

  .Parameters.Add("?OUT_RESULT",MySqlDbType.Int16.).Direction = ParamterDirection.Output

  .CommandType = CommandType.StoredParameter

End With


Reference:

https://www.vbforums.com/showthread.php?733665-RESOLVED-Insert-date-into-mysql

No comments :

Post a Comment