我已经定义了以下函数,它将从表中返回 3 列。
public DataSet GetFunc()
{
int iRet = 0;
DataSet ds = new DataSet();
SqlConnection sqlConnection = new SqlConnection();
try
{
iRet = connect(ref sqlConnection);
if (DB_SUCCESS_CONNECT == iRet)
{
SqlCommand sqlCommand = new SqlCommand("", sqlConnection);
String strQuery = "Select ID, Did, FirstName from Users";
sqlCommand.CommandText = strQuery;
SqlDataAdapter adaptor = new SqlDataAdapter(sqlCommand);
adaptor.Fill(ds);
sqlConnection.Close();
return ds;
}
}
catch (Exception e)
{
disconnect(ref sqlConnection);
}
}
但是当我尝试构建它时,我收到了错误:
错误 172“GetFunc()”:并非所有代码路径都返回值
我很困惑我哪里出错了。有人可以指导我吗?