UPDATE statement on MDB failes

L

Lander Debeuf

the UPDATE statement with the OleDbCommand class wont work with me :(
i cant seem to get it right

i use for an example the following statement:

'update tbl_DynCountry set Country = @Country where CountryID = @CountryID'

then i add the parameters, and i add the database connection to the command!

when i am in debugmode, everything seems ok, dataconnection is open,
parameters are attached, with the right value,
then i use the method

command.ExecuteNonQuery();

and the return value is 0 -- meaning 0 rows affected!

i cant seem to find the problem :(

insert statements are working fine, but the update aint :(

did anybody have the same problem in the past??? and how do i solve it?
 
N

Norman Yuan

You need to show the code of how the two parameters are added into commnd's
Parameters collection.

A very important thing when using OleDb namespace, the parameter name does
not paly a role, while the order fo a parameter is added into the Parameters
collection is very important. In your case, the first parameter in the
Parameter colletion would be used for updating "Country" column, while the
second parameter would be used in WHERE clause, even that parameter is not
named as "@CountryID".

This issue often is overlooked in many (if not most) .NET books, samples. I
should point out, it applies to both "INSERT INTO..." and "UPDATE...", even
your insertion seems work.

I had exepierence on this seemed correct insertion: yes, records get
inserted, but the values in the columns could be wrong, if you rely on
parameter's name, not its index order.
 

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

Top