Getting Exception “not all code path return a value”

前端 未结 3 1016
春和景丽
春和景丽 2021-01-22 00:34

Hi I have a method which updates a MySQL table using a query. I\'m using a MS Visual Studio and phpmyadmin as the SQL client.

Method:

public static Memb         


        
3条回答
  •  情深已故
    2021-01-22 00:50

    An alternative to the post of @Sajeetharan is that you return the value of your ExecuteNonQuery call

    connection.Open();
    cmd = connection.CreateCommand();
    cmd.CommandText = query;
    return cmd.ExecuteNonQuery();
    

    Of course you also have to return something at the end of your method (after the finally block).

    For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

    Reference

提交回复
热议问题