asp.net中自定义验证控件的简单用法

         private   void  CustomValidator1_ServerValidate( object  source, System.Web.UI.WebControls.ServerValidateEventArgs args)
        
{
            
string username=args.Value;
            OleDbConnection conn 
= new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+HttpContext.Current.Server.MapPath("db.mdb"));
            conn.Open();
            OleDbCommand cmd
=new OleDbCommand("select Count(*) from GuestBook where Username='"+this.TextBox8.Text+"'",conn);
            
int count=Convert.ToInt32(cmd.ExecuteScalar());
            
if(count>0)
            
{
                args.IsValid
=false;
            }

            
else
            
{
                args.IsValid
=true;
            }


            conn.Close();
        }
这里使用的是ACCESS数据库

你可能感兴趣的:(asp.net)