且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

帮助并非所有代码路径都返回值

更新时间:2023-02-05 12:35:57

您需要返回类型为MySqlConnection的对象.在这种情况下,它应该是con.
You need to return an object of type MySqlConnection. In this case that would be con.


该方法必须返回一个MySqlConnection对象. 大概
That method must return a MySqlConnection object.
Probably
return con;


只需在大括号前即可解决问题.
:rolleyes:


just before the closing curly bracket will do the trick.
:rolleyes:


问题是,您没有返回MySqlConnection.您可以做的是:

the problem is, that you are not returning a MySqlConnection. What you could do is:

public static MySqlConnection m_con;

public static MySqlConnection GetConnection(string server, string user, string password, string db)
{
    string str = "Server='" + server + "';user='" + user + "';password='" + password + "';database='" + db + "';";
    m_con = new MySqlConnection(str);
    con.Open();
    isConnected = true;
    return m_con;
}