c# - Is there a way to display an error message if the table is not updated? -


i want update row in table:

try {     string sql ="update tablename set firstname ='john' id = 123";      mysqlcommand command = new mysqlcommand(sql, connection);     connection.open();      command.executenonquery(); } catch (exception) { } {     connection.close(); } 

based on id (key), works if id in table, if id doesn't exist in table shows no error message.

is there way can know if id not found?

actually executenonquery returns number of rows affected. can make use of that:

int affectedrows = command.executenonquery();  if (affectedrows == 0) {     // show error; } else {     // success; } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -