Proper code but can't insert to database

Posted by Dchris on Stack Overflow See other posts from Stack Overflow or by Dchris
Published on 2012-11-24T13:49:26Z Indexed on 2012/11/24 23:04 UTC
Read the original article Hit count: 150

I have a Visual Basic project using Access database.I run a query but i don't see any new data on my database table.I don't have any exception or error.Instead of this the success messagebox is shown. Here is my code:

    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

What is the problem?

© Stack Overflow or respective owner

Related posts about database

Related posts about vb.net