asp.net用户注册时的验证

2014 年 10 月 22 日2630

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

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 SettingsAdministratorMy DocumentsVisual Studio ProjectsWebApplication1 (2)databasedb1.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 SettingsAdministratorMy DocumentsVisual Studio ProjectsWebApplication1 (2)databasedb1.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

/////

////

查看本文来源

0 0