一个关于c#.net返回值的问题

来源:百度知道 编辑:UC知道 时间:2024/05/10 20:56:16
各位大虾帮帮忙啦~~
我在vs.net2005中写了以下一段代码:
public string SelectRole(string NO,string CardID,string Role)
{
if(Role=="学生")
{
string sql="select count(*) from student where SID='"+NO+"' and SCardID='"+CardID+"'";
return sql;
}
else
{
string sql="select count(*) from Teacher where TID='"+NO+"' and TCardID='"+CardID+"'";
return sql;
}

}
出现错误提示如下:
并非所有的确代码路径都返回值!
怎么改呀~不会呀~偶系菜乌别骂偶~~

改成:
public string SelectRole(string NO,string CardID,string Role)
{
string result="";
if(Role=="学生")
{
result="select count(*) from student where SID='"+NO+"' and SCardID='"+CardID+"'";

}
else
{
result="select count(*) from Teacher where TID='"+NO+"' and TCardID='"+CardID+"'";
}
return result;
}

public string SelectRole(string NO,string CardID,string Role)
{
if(Role=="学生")
{
string sql="select count(*) from student where SID='"+NO+"' and SCardID='"+CardID+"'";
return sql;
}
string sql="select count(*) from Teacher where TID='"+NO+"' and TCardID='"+CardID+"'";
return sql;
}

看看这样行不?