Updating Row value when PK is known

  • Thread starter Thread starter Aziz
  • Start date Start date
A

Aziz

I am using VB.NET 2003

I have a simple Dataset DataTable (call it StockLevels) such as this:

BaseMetalCode (PK) BaseMetalInStock
Ag 1000
Zn 700
Si 1300
Cu 2300
etc etc

If know the value of the PK (Zn), how do I update the BaseMetalInStock
related field for it?

If I use:
dsDataset.StockLevels.FindByBaseMetalCode("Zn").BaseInStock =
CInt(1000)

I get this error:
Object reference not set to an instance of an object.

It's probably very easy to solve but how?
 
Hi Aziz,

1. Make sure that BaseMetalCode is indeed a primary key in DataTable.
2. Check out which part of your expression yields error.
 
OK I solved that problem (forgot to fill the DataSet, doh) but now I
get:
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

pointing to the update command.

dsDataset.StockLevels.FindByBaseMetalCode("Zn").BaseInStock =
CInt(1000)
daBaseMetalStocks.Update(dsDataset, "BaseMetalStocks")

My database PKs and XML Schema definitions are all OK. The table is a
parent table and all my DataAdapters are filled in the correct order.
 
The error is:
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

pointing to the Update daBaseMetalStocks.Update(dsDataset,
"BaseMetalStocks") command.

I've defined all the Update/Insert/Delete commands through the
DataAdapter configuration. I did it the same as my other tables and
they work fine. I've also tried disabling EnforceConstraints but it
makes no difference.

I've heard deleting all tables in the XML Designer and regerating the
DataSet can help, is this right?
 
There should be error description (exception.Message) which should describe
the issue better.
Also there is call stack...
 
After a lot of experimenting I got it working by deleting the
relationship in my Access Database. (I created a dummy table similar to
BaseMetalStocks, defined the DA and XML Schema)

But why does it not work? I have exactly the same relationships in my
XML Schema as I have in the access database. The BaseMetalStocks and
the dummy table I created are both Foreign keys in another table with a
composite PK. Is there a known issue with linking to composite PK
tables?

One last Question: will it be OK if the access database itself doesn't
have the relationship as long as the XML Schema has the relationship
defined?
 
Back
Top