科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道asp.net用户注册时的验证

asp.net用户注册时的验证

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

////验证用户名是否与注册数据库中的重名!!!

作者:中国IT实验室 来源:中国IT实验室 2007年9月3日

关键字: 验证 用户注册 ASP.NET Web站点 Web标准

  • 评论
  • 分享微博
  • 分享邮件

////验证用户名是否与注册数据库中的重名!!!

Private Sub check_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles check.Click
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String

dbname = Server.MapPath("db1.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WebApplication1 (2)\database\db1.mdb")数据库所在的目录
If userid.Text = "" Then
Label5.Text = "error!!you must complete it"
Else

Dim checklogin As String
checklogin = "select * from users "

Dim cmd As New OleDbCommand(checklogin, myConnection)
Dim reader As OleDbDataReader

Try
myConnection.Open()
reader = cmd.ExecuteReader()
reader.Read()

If userid.Text = reader("userid") Then
Label5.Text = "the userid had been used"
Else
Label5.Text = "this userid can use"
End If
Catch err As Exception
Trace.Write(err.Message)

Label5.Text = "checked error"
Finally
If (Not myConnection Is Nothing) Then
myConnection.Close()
End If

End Try
End If
End Sub

////用户注册

Private Sub regist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles regist.Click
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath("db1.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WebApplication1 (2)\database\db1.mdb")
Dim strinsert As String
strinsert = "insert into users("
strinsert &= "u_id,u_password)"
strinsert &= "values('"
strinsert &= userid.Text & "','"
strinsert &= password.Text & "')"
Dim cmd As New OleDbCommand(strinsert, myConnection)
Dim added As Integer
Try
myConnection.Open()
added = cmd.ExecuteNonQuery
If added > 0 Then

Label5.Text = "your information is added"
Response.Redirect("home.aspx")

End If
Catch err As Exception
Trace.Write(err.Message)
Label5.Text = "added error"
Finally
If (Not myConnection Is Nothing) Then
myConnection.Close()
End If
End Try

End Sub

/////

////

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章