用C#写一个验证函数

来源:百度知道 编辑:UC知道 时间:2024/06/07 07:58:06
public Boolean datacheck(string inputdata)
{

com.CommandText ="select count(*) from baseimformation where code='"+ inputdata +"'";
if( com.ExecuteScalar ==0)
return true;
else
return false;

}
这样写总是有错误,请高手指点。谢谢

public Boolean datacheck(string inputdata)
{
//这里应该是数据库连接
com.CommandText ="select count(*) from baseimformation where code='"+ inputdata +"'";

return com.ExecuteScalar().Equals("0");

}

com.ExecuteScalar后面少了括号。

public Boolean datacheck(string inputdata)
{

com.CommandText ="select count(*) from baseimformation where code='"+ inputdata +"'";
int count = Convert.ToInt32(com.ExecuteScalar());
if(count>0)
return true;
else
return false;
}

if(com.ExecuteCommand()==0)