//建立一个静态方法用于返回用户的登录情况
public static bool Logon(string userid,string password)
{
try
{
string str=ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn=new SqlConnection(str);
conn.Open();
SqlCommand comm=new SqlCommand("select count(*) from logon where uid='"+userid+"' and pwd='"+password+"'",conn);
int count=Convert.ToInt32(comm.ExecuteScalar());
if (count>0)
{
return true;
}
else
{ return false;
}
}
catch
{
}
}请问,我写的方法在访问时,,,出错"提示:并非每个方法都有返回值",,,请问大家,应该怎么改???多谢
public static bool Logon(string userid,string password)
{
try
{
string str=ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn=new SqlConnection(str);
conn.Open();
SqlCommand comm=new SqlCommand("select count(*) from logon where uid='"+userid+"' and pwd='"+password+"'",conn);
int count=Convert.ToInt32(comm.ExecuteScalar());
if (count>0)
{
return true;
}
else
{ return false;
}
}
catch
{
}
}请问,我写的方法在访问时,,,出错"提示:并非每个方法都有返回值",,,请问大家,应该怎么改???多谢
catch()
{}
return false;
}
==========
另外你书写程序的方式不太好
应该
bool bResult;
try{
if(条件)
bResult =true;
else
bResult = false;
}
catch()
{
throw ...}
return bResult;
如果try{...}有异常, 这个方法就不会返回任何值了
出错提示很清楚了
{
return false;
}