How to get no of records updated

More
7 years 2 weeks ago #532 by drazen
Is there any way to get no of records updated/deleted when using CCommand.Open method (DBROWCOUNT)?
Eg, Oracle OLEDB provider always returns no of records, for SELECT, UPDATE, DELETE, etc.

Please Log in or Create an account to join the conversation.

More
7 years 2 weeks ago #533 by Moderator
There should be a separate method Execute with the parameter:
CCommand<CNoAccessor, CNoRowset> cmd;
DBROWCOUNT* pRowsAffected;
. . .
cmd.Execute(. . ., pRowsAffected, . . .);
.

Please Log in or Create an account to join the conversation.

More
7 years 2 weeks ago #534 by drazen
cmd.Open calls ExecuteAndBind that calls Execute and RowsAffected is always -1 (from ICommand::Execute method).
Should I set some properties to get correct number of rows affected?

Please Log in or Create an account to join the conversation.

More
7 years 1 week ago #538 by Moderator
Here is fragment of code I used, and the number of affected rows was returned correctly:
#include <atldbcli.h>
CDataSource dataSource;
CSession session;
HRESULT hr = dataSource.OpenFromInitializationString(CONN_STR);
hr = session.Open(dataSource);

// Start transaction
hr = session.StartTransaction();

// update a record in contact table
CCommand<CNoAccessor, CNoRowset> cmd;
DBROWCOUNT rowsAffected;
hr = cmd.Open(session, "UPDATE contact SET fname='test' WHERE contact_id=1", NULL, &rowsAffected, DBGUID_DBSQL, false);
cmd.Close();

// delete records
hr = cmd.Open(session, "DELETE FROM contact WHERE contact_id<>1", NULL, &rowsAffected, DBGUID_DBSQL, false);
cmd.Close();

// Rollback transaction
session.Abort();

What version of PGNP Provider are you using? Would you send sample code to reproduce the issue?

Please Log in or Create an account to join the conversation.

Time to create page: 0.145 seconds
Powered by Kunena Forum