asp.net用戶注冊(cè)時(shí)的驗(yàn)證
2024-07-10 12:57:25
供稿:網(wǎng)友
 
////驗(yàn)證用戶名是否與注冊(cè)數(shù)據(jù)庫中的重名!!!
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")數(shù)據(jù)庫所在的目錄
 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
 
////用戶注冊(cè)
 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
/////
 
////