帮助并非所有代码路径都返回值 [英] HELP Not all code paths return a value
本文介绍了帮助并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我使用代码
Well im using the code
public static MySqlConnection GetConnection(string server, string user, string password, string db)
{
string str = "Server='" + server + "';user='" + user + "';password='" + password + "';database='" + db + "';";
MySqlConnection con = new MySqlConnection(str);
con.Open();
isConnected = true;
}
而且我似乎无法弄清楚为什么它会给我错误:并非所有代码路径都返回一个值,我想知道是否有人可以通过this
And i cant seem to figure out why its giving me the error :Not all code paths return a value, i was wondering if someone could help me out with this
推荐答案
您需要返回类型为MySqlConnection
的对象.在这种情况下,它应该是con
.
You need to return an object of typeMySqlConnection
. In this case that would becon
.
该方法必须返回一个MySqlConnection
对象. 大概
That method must return aMySqlConnection
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;
}
这篇关于帮助并非所有代码路径都返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文