0

I have been trying to insert a row into an access database. I have been able to insert into other tables using the same format, but this table seams to have an issue. I have dropped the table and recreated it, and that didn't seam to work. So I figured I would see if someone can see what my issue is. Here is my insert code in visual studio

    Dim objcon As New ConnectString   
    Dim cmd As New OleDbCommand("INSERT INTO Order(OrderId, CustomerId, EmployeeId) VALUES (@OrderId, @CustomerId, @EmployeeId);", objcon.con)

    With cmd.Parameters
        .AddWithValue("@OrderId", CInt(txtOrderId.Text))

        .AddWithValue("@CustomerId", CInt(txtCustId.Text))
        .AddWithValue("@EmployeeId", CInt(txtEmployeeId.Text))


    End With
    objcon.con.Open()
    cmd.ExecuteNonQuery()
    objcon.con.Close()

The connectstring works in all my other classes, so I don't think it is the issue. The only difference in this table compared to my other tables is that it has foreign keys (customerId and EmployeeId). Can anyone see what the issue is?

  • What error msg are you getting? It sounds like the value(s) of the foreign-key(s) do not have corresponding entries in the associated primary key table(s) – ron tornambe Apr 16 '14 at 17:54
  • Wrap the code in a Try Catch and see what the error is. And look into what ron tornambe said above. He's right I'm sure. – thetimmer Apr 16 '14 at 17:56

0 Answers0