OdbcCommand.ExecuteNonQuery return question

jwu1023

Member
Joined
Jan 9, 2006
Messages
13
Location
Memphis, TN
Programming Experience
3-5
Dear all,

I used OdbcCommand.ExecuteNonQuery to run a insert query and it worked. However, the return value of this command is -1, even though thousands of rows inserted into the table already.

From the dynamic help of OdbcCommand.ExecuteNonQuery:
"For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1."

I wonder how could -1 return in my case. Does that mean rollback occured?
How can I know how many rows inserted in my table?

If anyone can help? I do appreciate.
 
If your query was of the form such that many rows were inserted as a result of one statement:

INSERT INTO table (SELECT stuff FROM otherTable)

Then it may be that the value you get back was indeed -1 because the database didnt count the rows.

It might also be the case that the data provider youre using doesnt implement counting. You've stated youre using ODBC, but nothing more, so I can make no futther guesses. If you were to tell me what target DB you are inserting to I might be able to provide more info.
 
Back
Top