c#中CustomValidator1控件写完代码后不起作用,我想弄个登录验证
stringstrCon="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath("tushuguan...
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("tushuguan.mdb");
//----连接数据库
OleDbConnection con = new OleDbConnection(strCon);
con.Open();
OleDbCommand cmd = new OleDbCommand("select count(*) from huiyuan where [user]='" + tbhy.Text + "'",con);
int count;
//----将查询后的值返回给count用来做后面的判断
count = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
//----判断用户名是否存在,并返回一个bool
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
} 展开
//----连接数据库
OleDbConnection con = new OleDbConnection(strCon);
con.Open();
OleDbCommand cmd = new OleDbCommand("select count(*) from huiyuan where [user]='" + tbhy.Text + "'",con);
int count;
//----将查询后的值返回给count用来做后面的判断
count = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
//----判断用户名是否存在,并返回一个bool
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询