asp.net用户注册时的验证
2024-07-10 12:57:25
供稿:网友
////验证用户名是否与注册数据库中的重名!!!
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
/////
////