• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

asp.net用户注册时的验证

发布: 2007-7-14 20:06 | 作者: 佚名    | 来源: 网络转载     | 查看: 72次 | 进入软件测试论坛讨论

领测软件测试网 ////验证用户名是否与注册数据库中的重名!!!
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

/////

 

////

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网