markzzz
markzzz

Reputation: 47947

How to count the number of updated row

I have an access database, and I do this query :

OleDatabase OleDB = new OleDatabase("MyDatabase");
string comando = "UPDATE ANAGRAFICA SET DENOMINAZIONE='" + aziendaValue["nome"] + "', INDIRIZZO='" + aziendaValue["indirizzo"] + "' WHERE PIVA='" + aziendaValue["piva"] + "'";
OleDB.oleComando(comando);

How can I check how many rows (0 to n) the query update?

Upvotes: 0

Views: 1312

Answers (3)

user610650
user610650

Reputation:

I'm not 100% on this since I haven't touched MS Access in a while, but I'm pretty sure that with ExecuteNonQuery you get the number of updated records, for example:

OleDbCommand command = new OleDbCommand("UPDATE SomeTable SET SomeColumn='SomeValue'", SomeConnection);
int updated_records_count = command.ExecuteNonQuery();

Upvotes: 2

Paolo Falabella
Paolo Falabella

Reputation: 25834

You should use OleDbCommand.ExecuteNonQuery. It returns the number of affected rows.

Upvotes: 1

Matteo Monti
Matteo Monti

Reputation: 8930

First thing you can do is: "SELECT COUNT(*) FROM ANAGRAFICA WHERE PIVA="+aziendaValue["piva"]. It takes a query more, but it should actually work and if you don't have problems with efficiency doing it is safe for sure!

Upvotes: 0

Related Questions