我有一个使用 Access 数据库的 Visual Basic 项目。我运行查询,但在我的数据库表上没有看到任何新数据。我没有任何异常或错误。而不是显示成功消息框。这是我的代码:
Dim ID As Integer = 2
Dim TableNumber As Integer = 2
Dim OrderDate As Date = Format(Now, "General Date")
Dim TotalPrice As Double = 100.0
Dim ConnectionString As String = "myconnectionstring"
Dim con As New OleDb.OleDbConnection(ConnectionString)
Try
Dim InsertCMD As OleDb.OleDbCommand
InsertCMD = New OleDb.OleDbCommand("INSERT INTO Orders([ID],[TableNumber],[OrderDate],[TotalPrice]) VALUES(@ID,@TableNumber,@OrderDate,@TotalPrice);", con)
InsertCMD.Parameters.AddWithValue("@ID", ID)
InsertCMD.Parameters.AddWithValue("@TableNumber", TableNumber)
InsertCMD.Parameters.AddWithValue("@OrderDate", OrderDate)
InsertCMD.Parameters.AddWithValue("@TotalPrice", TotalPrice)
con.Open()
InsertCMD.ExecuteNonQuery()
MessageBox.Show("Successfully Added New Order",
"Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
con.Close()
Catch ex As Exception
'Something went wrong
MessageBox.Show(ex.ToString)
Finally
'Success or not, make sure it's closed
If con.State <> ConnectionState.Closed Then con.Close()
End Try
问题是什么?