okay have created log in system on vb.net using database on access. problem having of username , password combinations work perfectly, of them, although put in correctly, don't work @ all. code have written...
private sub button1_click(sender object, e eventargs) handles button1.click ' check if username or password empty if textpassword.text = "" or textusername.text = "" messagebox.show("please complete required fields..", "authentication error", messageboxbuttons.ok, messageboxicon.error) else ' both fields supplied ' check if user exist in database ' connect db dim conn new system.data.oledb.oledbconnection() conn.connectionstring = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\database1.accdb" 'conn.open() 'msgbox("susscess") dim sql string = "select * accounts username='" & textusername.text & "' , password = '" & textpassword.text & "'" dim sqlcom new system.data.oledb.oledbcommand(sql) 'open database connection sqlcom.connection = conn conn.open() dim sqlread system.data.oledb.oledbdatareader = sqlcom.executereader() if sqlread.read() memberpage.show() me.hide() else ' if user enter wrong username , password combination ' throw error message messagebox.show("username , password not match..", "authentication failure", messageboxbuttons.ok, messageboxicon.exclamation) 'clear fields textpassword.text = "" textusername.text = "" 'focus on username field textusername.focus() end if end if end sub
it seems mistake happening @ condition checking after filling datareader. i.e
if sqlread.read() try if condition following code
if not sqlread nothing if doesnt work then..
i suggest using dataadapter , check whether returns rows. if row count greater 1 , must show memberpage
private sub button1_click(sender object, e eventargs) handles button1.click if textpassword.text = "" or textusername.text = "" messagebox.show("please complete required fields..", "authentication error", messageboxbuttons.ok, messageboxicon.error) else dim conn new system.data.oledb.oledbconnection() conn.connectionstring = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\database1.accdb" dim sql string = "select * accounts username='" & textusername.text & "' , password = '" & textpassword.text & "'" dim sqlcom new system.data.oledb.oledbcommand(sql) dim ds dataset sqlcom.connection = conn conn.open() 'dim sqlread system.data.oledb.oledbdatareader = sqlcom.executereader() dim da new oledbdataadapter(sqlcom) da.fill(ds) if ds.tables(0).rows.count > 1 memberpage.show() me.hide() else messagebox.show("username , password not match..", "authentication failure", messageboxbuttons.ok, messageboxicon.exclamation) textpassword.text = "" textusername.text = "" textusername.focus() end if end if end sub
Comments
Post a Comment