帮我看一下这个返回bool值的语句怎么改才好
public bool ReturnRID()
{
string id = DetailsView1.DataKey.Value.ToString();
SqlDataReader sdr = null;
user getUser = new user();
sdr = getUser.SelectRIDFromBorrow();
while (sdr.Read())
{
if (id == sdr[ "RID "].ToString())
{
return true;
}
else
{
return false;
}
}
}
提示“并非所有的代码路径都有返回值”,我该怎么改呢?
------解决方案--------------------while (sdr.Read())
{
if (id == sdr[ "RID "].ToString())
{
return true;
}
}
return false;
------解决方案--------------------public bool ReturnRID()
{
string id = DetailsView1.DataKey.Value.ToString();
SqlDataReader sdr = null;
user getUser = new user();
sdr = getUser.SelectRIDFromBorrow();
while (sdr.Read())
{
if (id == sdr[ "RID "].ToString())
{
return true;
}
}
return false; // < < < < < < < < <
}
------解决方案--------------------public bool ReturnRID()
{
string id = DetailsView1.DataKey.Value.ToString();
SqlDataReader sdr = null;
user getUser = new user();
sdr = getUser.SelectRIDFromBorrow();
while (sdr.Read())
{
if (id == sdr[ "RID "].ToString())
{
return true;
}
//else
//{
//return false;
//}
}
return false; //换到这个地方,暴露出来
}
------解决方案--------------------。。。
zswang(伴水清清)(专家门诊清洁工)
正解