Running sql SubQueries in asp.net c# -
hello working on mycollege project , trying make user login application in asp.dot net. have 2 tables in database 1 customer full detail , other customer login detail want count row in first query , if login_id , password matches executes other query retrive , displays customer first name, on redirectedd page below have done other type of method welcomed here code
protected void login1_authenticate(object sender, authenticateeventargs e) { sqlconnection connection = new sqlconnection(conn); connection.open(); cmd = new sqlcommand("select count(*) customer_login login_id = @a , pass_login=@b",connection); cmd.parameters.addwithvalue("@a", login1.username); cmd.parameters.addwithvalue("@b", login1.password); string user_name; int = convert.toint32(cmd.executescalar().tostring()); if (i == 1) { e.authenticated = true; cmd = new sqlcommand("select f_name customer id = (select cust_id customer_login login_id = @a)", connection);//this query runs in mssms gives error in aspx // cmd.parameters.addwithvalue("@c",new sqlcommand ("select cust_id customer_login login_id = @a")); //cmd.parameters.addwithvalue("@a", login1.username); sdr = cmd.executereader(); sdr.read(); user_name = sdr["f_name"].tostring(); sdr.close(); if (session["productid"] != null) { session["user"] = user_name.tostring(); response.redirect("~/detail/cart.aspx"); } else { response.redirect("default.aspx"); } } else { e.authenticated = false; } }
the problem gives following error "incorrect syntax near keyword 'select'. must declare scalar variable "@a". " thanku
because have not assigned value @a
cmd = new sqlcommand("select f_name customer id = (select cust_id customer_login login_id = @a)", connection); cmd.parameters.addwithvalue("@a",value);
Comments
Post a Comment