得到异常“并非所有代码路径都返回值".

编程入门 行业动态 更新时间:2024-10-27 08:40:00
本文介绍了得到异常“并非所有代码路径都返回值".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一种使用查询更新MySQL表的方法.我正在使用MS Visual Studio和phpmyadmin作为SQL客户端.

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.

方法:

public static Member updateMember(string un, string pass, string name, string surname, string mf, string dob, string add, string phone, string email) { MySqlConnection connection = new MySqlConnection(conn); MySqlCommand cmd; string query = "UPDATE MEMBER SET Name='" + un + "', Surname='" + surname + "', MF='" + mf + "', DOB='" + dob + "', Address='" + add + "', PhoneNo='" + phone + "', EMail='" + email + "', UserName='" + un + "', Password='" + pass + "' "; tr y { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = query; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection.State == System.Data.ConnectionState.Open) { connection.Close(); } } }

这是正在发生的事情.我将文本框中的某些值以字符串变量的形式存储.然后,我将这些字符串变量发送到此方法.我希望该方法可以捕获我的字符串变量,并使用变量的值更新我的SQL表.

Here is what's happening. I'm storing some values from TextBoxes in a form in string variables. Then I'm sending those string variables to this method. I want that this method grabs my string variables and update my SQL table with the values of my variables.

我遇到错误,并非所有代码路径都返回值.

I'm getting an error not all code paths return a value.

推荐答案

您的方法未返回任何内容,您需要返回成员对象.

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)

更多推荐

得到异常“并非所有代码路径都返回值".

本文发布于:2023-11-10 01:20:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   返回值   异常   代码   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!