c# - Login to SQL Server database not working -
i trying make log in page in c# web page. have written code think correct. user supposed key in correct username , password. before go further modifying after success log in temporarily set label 1 show me whether it's correct or not. doesn't work , every time tried key in correct data, show "failed".
protected void imagebutton1_click(object sender, imageclickeventargs e) { sqlconnection con = new sqlconnection(); con.connectionstring = ("data source=localhost;initial catalog=seminardb; integrated security=true;"); try { con.open(); string str = "select * member username='" + signintext.text + "' , password='" + passwordtext.text + "'"; sqlcommand cmd = new sqlcommand(str, con); sqldatareader dr = cmd.executereader(); string login = signintext.text; string pwd = passwordtext.text; while (dr.read()) { if ((dr["username"].tostring() == login) && (dr["password"].tostring() == pwd)) { label1.text = "success!"; visibl = true; } else { label1.text = "failed!"; } } dr.close(); con.close(); } catch (exception ex) { label1.text = ex.message; } }
try this, hope works
protected void imagebutton1_click(object sender, imageclickeventargs e) { sqlconnection con = new sqlconnection(); con.connectionstring = ("data source=localhost;initial catalog=seminardb; integrated security=true;"); try { con.open(); string str = "select * member username='" + signintext.text + "' , password='" + passwordtext.text + "'"; sqlcommand cmd = new sqlcommand(str, con); sqldatareader dr = cmd.executereader(); if(dr.read()) { label1.text = "success!"; visibl = true; } else { label1.text = "failed!"; } con.close(); } catch (exception ex) { label1.text = ex.message; } }
Comments
Post a Comment