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数据库
posted @ 2006-04-01 18:34  拼博之路  阅读(823)  评论(3编辑  收藏  举报