Dim ConnString As String = "Data Source=localhost;" & _
                               "Initial Catalog=数据库名;User ID=sa;Password=123456"    Dim objCmd As New SqlDataAdapter("Select distinct * From 表名 &_ 
         Where 字段名='"& 文本名.text &"'", ConnString)    Dim DS As New DataSet()
    objCmd.Fill(DS, "表名")
    objconn.close()    Dim myTable As DataTable = DS.Tables("表名")
    Dim mycount as integer=myTable.rows.count  
    if mycount = 0 then
    response.redirect("b.aspx")
    else
    response.redirect("a.aspx")
    end if我的目的是接收注册页面传过来的用户名,然后用显示这个用户名的表的行的条数 来判断用户名是否重复, 重复跳转b.aspx,不重复跳转到a.aspx.这段代码没有错误,但不能达到目的,请高手帮我改一改.

解决方案 »

  1.   

    Dim ConnString As String = "Data Source=localhost;" & _
                                   "Initial Catalog=数据库名;User ID=sa;Password=123456"    Dim objCmd As New SqlDataAdapter("Select distinct * From 表名 &_ 
             Where 字段名='"& 文本名.text &"'", ConnString)    Dim DS As New DataSet()
        objCmd.Fill(DS, "表名")
            Dim myTable As DataTable = DS.Tables("表名")
        Dim mycount as integer=myTable.rows.count  
        if mycount = 0 then
        response.redirect("b.aspx")
        else
        response.redirect("a.aspx")
        end if我的目的是接收注册页面传过来的用户名,然后用显示这个用户名的表的行的条数 来判断用户名是否重复, 重复跳转b.aspx,不重复跳转到a.aspx.这段代码没有错误,但不能达到目的,请高手帮我改一改.
      

  2.   

    你用这样的SQL语句试试("Select count(*) From 表名 &_ 
             Where 字段名='"& 文本名.text &"'", ConnString)执行后取第一列的值。看看是否为0。