asp.net用户注册时的验证

80酷酷网    80kuku.com

  asp.net|用户注册////验证用户名是否与注册数据库中的重名!!!
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


/////



////

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: