Using c# how to receive value of a select statment (SQL) -
i want retrieve resulting value of select statement string variable. did successful login coding after want redirect page according roles retrieving database, if admin goes admin home page , if user goes user home page. below code there check out wrong.
protected void btn_lpc_login_click(object sender, eventargs e) { string strcon = configurationmanager.connectionstrings["sessionname"].connectionstring; string strselect = "select count(*) login_details email_id=@email_id , password =@password"; sqlconnection con = new sqlconnection(strcon); sqlcommand cmd = new sqlcommand(); cmd.connection = con; cmd.commandtype = commandtype.text; cmd.commandtext = strselect; sqlparameter username = new sqlparameter("@email_id", sqldbtype.nvarchar, 36); username.value = tbx_lpc_username.text.trim().tostring(); cmd.parameters.add(username); sqlparameter password = new sqlparameter("@password", sqldbtype.nvarchar, 50); password.value = tbx_lpc_password.text.trim().tostring(); cmd.parameters.add(password); con.open(); int result = (int32)cmd.executescalar();
here on words doubt :
if (result >= 1) { string strselect2 = "select roleid login_details email_id=@email_id"; if (srole == "user") { session.add("usnm", tbx_lpc_username.text); response.redirect("~/admin_pages/lpc_adm_homepage.aspx"); } else if (srole == "admin") { session.add("usnm", tbx_lpc_username.text); response.redirect("~/admin_pages/lpc_adm_settingspage.aspx"); } } else { clientscript.registerstartupscript(page.gettype(), "validation", "<script language='javascript'>alert('invalid username , password')</script>"); } }
string strselect2 = "select roleid login_details email_id=@email_id"; cmd.commandtext = strselect2; username = new sqlparameter("@email_id", sqldbtype.nvarchar, 36); username.value = tbx_lpc_username.text.trim().tostring(); cmd.parameters.add(username); int roleid = (int32)cmd.executescalar(); if (roleid == 2) //user { session.add("usnm", tbx_lpc_username.text); response.redirect("~/admin_pages/lpc_adm_homepage.aspx"); } else if (roleid == 1) // admin { session.add("usnm", tbx_lpc_username.text); response.redirect("~/admin_pages/lpc_adm_settingspage.aspx"); }
Comments
Post a Comment