VB.net COMExeption was unhandled -
i creating user login system using vb.net , ms access. unsure going wrong system , receive error message "item cannot found in collection corresponding requested name or ordinal" error coming in section "user.find(username)" on first line of loop. here code:
public class login dim loginerror string ' tell user wrong login public function login() dim dbconn new adodb.connection ' how tell visual studio 'how connect our database dim user new adodb.recordset 'we pass our argument through our recordset dim username string 'this our "query" dim struserdb string 'this sets email field in our database. dim strpassdb string 'same above password dim blnuserfound boolean 'i using "do" loop use 'this condition dbconn.open("provider = microsoft.jet.oledb.4.0;" & _ "data source = '" & application.startuppath & "\userdetails2000.mdb'") 'the inverted comas in dataouce statement itt keeps location of 'file 1 string. user.open("tbluserdetails", dbconn, adodb.cursortypeenum.adopenstatic, adodb.locktypeenum.adlockoptimistic) 'this table 'this connection 'these settings blnuserfound = false login = false username = "user = '" & txtemail.text & "'" 'this tells database find email field 'equivilent entered in textbox user.find(username) 'this full statement sends 'query' record set if user.bof = false , user.eof = false 'bof = begining of file, eof = end of file, tests whether database has 'reached sentinal value, if hasent username has been found, if has, 'the username has been found. struserdb = user.fields("email").value.tostring '"email" table field. setting struserdb username field of table strpassdb = user.fields("password").value.tostring if struserdb <> txtemail.text user.movenext() 'this if statement handles different case usernames, example, admin , admin 'we use if statement differentiate between different case letters else blnuserfound = true if strpassdb = txtpassword.text user.close() dbconn.close() return true else loginerror = "invalid password" user.close() dbconn.close() return false end if end if else loginerror = "invalid username" user.close() dbconn.close() return false end if loop until blnuserfound = true loginerror = "invalid username" user.close() dbconn.close() return false end function private sub btnlogin_click(byval sender system.object, byval e system.eventargs) handles btnlogin.click if login() = true messagebox.show("login succesful", "login status") else messagebox.show(loginerror, "login status") end if end sub
end class
verify tbluserdetails
contains column named user
.
maybe user
reserved keyword in access try setting username
as:
username = "[user] = '" & txtemail.text & "'"
Comments
Post a Comment