Getting Exception “not all code path return a value”

前端 未结 3 982
春和景丽
春和景丽 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

    0 讨论(0)
  • 2021-01-22 01:06

    Commonly, we need't return object like Member when update/insert or delete. We should return just a Boolean flag or return Nothing.

    If you return flag, you should set it as result of cmd.ExecuteNonQuery() > 0 and also in Catch brand.

    If you return nothing, just modify your method to

    public static void updateMember(...)
    {
        ....
    }
    
    0 讨论(0)
  • 2021-01-22 01:16

    Your method is not returning anything, You need to return the Member Object.

    If you do not need to return anything , just change your Method Signature like this,

    public static Void updateMember(string un, string pass, string name, string surname,string mf, string dob, string add, string phone, string email)
    
    0 讨论(0)
提交回复
热议问题