Reputation: 427
I have been making some test processes which execute queries on a netezza database. I was just wondering if there is a way to get back any output such as rows updated, or how to catch any error messages. As it is right now it is in a normal try/catch block, but if a query failed would that be returned as an exception or would the program just continue because no error/output was received?
Basically what I'd like to do is in the console writeout below I'd like it to write out the output each time it loops, and then write out the error if there is one. For instance when I use an interface to do the queries with it will just scroll saying " blah blah blah executed, 1 row updated", or will return an error message if there is a problem.
Below is the code:
try
{
netezzaConn = new OleDbConnection(connString);
netezzaConn.Open();
for(int i = 0; i < recordCounts.Count; i++) {
if(recordCounts[i].RecordCount.ToString() != recordCounts[i].OrigCount.ToString()) {
string updateStatement = myquery;
Console.WriteLine("Executing query : " + updateStatement);
OleDbCommand exe = new OleDbCommand(updateStatement, netezzaConn);
exe.ExecuteNonQuery();
} else {
Console.WriteLine("No records were removed from the file : " + recordCounts[i].FileName + ". Not updating Netezza.");
}
}
netezzaConn.Close();
}
Upvotes: 1
Views: 477
Reputation: 31
Did some research on this and you must use a return int...
int rowsAffected = command.ExecuteNonQuery();
The rowsAffected will show how many rows have been changed.
Upvotes: 2