似乎无法将此传递给数据库我认为查询存在问题,任何帮助都表示赞赏。VS没有给出任何错误,这导致我认为问题与声明有关,遗憾的是我无法在navicat中测试它,因为它不是真正的价值观#34;我尝试使用像这样的参数
Params.Add(New MySqlParameter(" @ eventDate",eventDate))
和这样的参与者
Params.Add(New MySqlParameter(" eventDate",eventDate))
两者的结果相同
Public Function ParameterizedNonQueryCommand(ByRef NonQuery As String, ByVal Parameters As List(Of MySqlParameter), _
Optional ByVal Connection As MySql.Data.MySqlClient.MySqlConnection = Nothing) As Integer
Dim comm As New MySql.Data.MySqlClient.MySqlCommand(NonQuery, Connection)
Try
For Each param As MySql.Data.MySqlClient.MySqlParameter In Parameters
comm.Parameters.Add(param)
Next
If comm.Connection.State <> ConnectionState.Open Then comm.Connection.Open()
comm.Prepare()
Return comm.ExecuteNonQuery()
Catch ex As Exception
Return CType(False, Integer)
MessageBox.Show(ex.Message)
Finally
comm.Connection.Close()
comm.Dispose()
End Try
End Function
Dim query As String = "insert into so_events (date, user, ip, method, event, Staffed, Details, BackgroundColor, TextColor, Recurring, Font, TextSize, ToolTip)" _
& "values (@eventDate, @User, @ip, @ControlPanel, @EventName, @staffed, @cpEvents, @BackColor, @TextColor, @Recurring, @fontStyle, @fontSize, @allowTool)"
Dim Params As New List(Of MySqlParameter)
Params.Add(New MySqlParameter("@eventDate", eventDate))
Params.Add(New MySqlParameter("@User", frmMain.user))
Params.Add(New MySqlParameter("@ControlPanel", "ControlPanel"))
Params.Add(New MySqlParameter("@EventName", eventName))
Params.Add(New MySqlParameter("@staffed", staffed))
Params.Add(New MySqlParameter("@cpEvents", cpEvents))
Params.Add(New MySqlParameter("@BackColor", BackColor))
Params.Add(New MySqlParameter("@TextColor", TextColor))
Params.Add(New MySqlParameter("@Recurring", Recurring))
Params.Add(New MySqlParameter("@fontStyle", fontStyle))
Params.Add(New MySqlParameter("@fontSize", fontSize))
Params.Add(New MySqlParameter("@allowTool", allowTool))
Dim oConnection As MySqlConnection = New MySqlConnection("Data Source=********;Database=*******;User ID=********;Password=*********;")
frmPanel.ParameterizedNonQueryCommand(query, Params, oConnection)