| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 286 人关注过本帖
标题:帮助检查注册页面中验证用户名是否为重的.net vb版的代码
收藏  订阅  推荐  打印 
cannie2008
Rank: 1
等级:新手上路
帖子:4
积分:144
注册:2008-7-11
帮助检查注册页面中验证用户名是否为重的.net vb版的代码

新手刚学编程,做注册页面  其中用户名需要验证是否已被用,我使用的customvalidation控件,出现的问题是无论是输入什么值都是反应errormessage的值 代码如下:
控件的属性如下:
clientValidationFunction=CustomValidator1_ServerValidate;
controltovalidate=username;//usernanme 为textbox的id
enableclientscipt=true
enabled=true;
enableviewstate=true
visible=true  
errormessage=已被注册   
不知是不是控件属性没有设好

函数代码:
Private Sub CustomValidator1_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim connstring As String = "data source=JZHOST2\SQL1;initial catalog=piman; user id=sa;pwd=cannie"
        Dim myconn As New SqlConnection(connstring)
        myconn.Open()
           
        Dim s As String
        s = "select username from huiyuan"  huiyuan为数据表,验证username 是否被用
        Dim mycommand As New SqlDataAdapter(s, myconn)

        Dim ds As DataSet
        ds = New DataSet
        mycommand.Fill(ds, "huiyuan")

        Dim dv As DataView
        dv = ds.Tables(0).DefaultView
        Dim datarow As DataRowView

        Dim txt As String
        args.IsValid = True
        For Each datarow In dv
            txt = datarow.Item("username").ToString()
            If txt = args.Value Then
                args.IsValid = False
                Exit For
            End If
        Next
    End Sub


大家帮忙看看 多谢  多谢

[ 本帖最后由 cannie2008 于 2008-7-14 09:29 编辑 ]
搜索更多相关主题的帖子: 用户名  代码  页面  控件  验证  
2008-7-14 09:21
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.049141 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved