Inappropriate "related record" error updating from a datagrid?

Inappropriate referential integrity errors from datagrid update

In a very simple program to update the Northwind Customers (MS Access) from VB.net datagrid, I get the error "The record cannot be deleted or changed because table 'Orders' includes related records." Now, I understand what the message is supposed to mean, but I haven't modifed any Customers ID fields, only harmless fields like City and the like. It appears to think I'm changing primary keys when I'm not. The OleDataadapter does "Select * from Customers" and I let VB generate the update, delete, etc (which it does without errors). The code is very simple. Here's everything after the Windows generated code:

'=== Jet 4 data engine, NW database, Customers table
'=== Customers.CustomerID <==> Orders.CustomerID (chk ref. integ.)

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
...Ds1 = New ds
...Try
......da.Fill(Ds1, "Customers")
...Catch ex As Exception
......MessageBox.Show(ex.Message & vbCrLf _
.......& da.SelectCommand.CommandText)
......Exit Sub
...End Try
...DG.SetDataBinding(Ds1, "Customers")
End Sub

Private Sub btnGo_Click(ByVal sender As System.Object, _
.ByVal e As System.EventArgs) Handles btnGo.Click
...Try
......da.Update(Ds1, "Customers")
......MsgBox("Update Worked")
...Catch ex As Exception
......MessageBox.Show(ex.Message & vbCrLf _
.......& da.UpdateCommand.CommandText)
......Exit Sub
...End Try
...Form1_Load(sender, e)
End Sub

(Forgive periods, but this msg formatter drops spaces.)
I've done a repair on the database, just in case it was a misplaced pointer or something. Can anyone help? Much obliged!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories