I can find it, why can't my code?

P

PaulNaude

I have a problem deleting a record from a table with 3 primary keys, in code.
I get the values of the primary keys from my datagrid displaying the record
to be deleted as follows:
....
findTheseVals(0) = DataGrid4.Item(u, 0) 'First column and unique primary key
(no duplicates allowed)
findTheseVals(1) = DataGrid4.Item(u, 1) 'Second column and primary key
(duplicates ok)
findTheseVals(2) = DataGrid4.Item(u, 2) 'Third column and primary key
(duplicates ok)
....

Then, to delete the record from the table, I use

DataSet11.Tables("Equipment").Rows.Find(findTheseVals).Delete()

but get the following error:

An unhandled exception of type 'System.NullReferenceException' occurred in
App.exe
Additional information: Object reference not set to an instance of an object.

i.e. this record was not found, although I can physically see it in the table.

I checked the populated values of findTheseVals and it matches my primary
key values (and types) in the database table exactly.
The column orders in the dataAdapter, datagrid and database table are
identical.
I checked that the table referenced is exactly the same as the one
referenced by the datagrid etc.

When I manually delete the row from my datagrid, the record is correctly
deleted from the database.

What am I missing here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top