Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to verify from database that the user id and paswrd is correct i no that how to write querry but i dont no how to write it in sql command actually i want to fetch user id and passwrd from text box so how to write

SqlCommand cmd = new SqlCommand("SELECT * FROM admin where user_id='admin' and user_pwd='admin'");
the underline thing must be fetch from textbox and verify from database but how???
Posted

Try this:
C#
SqlCommand cmd = new SqlCommand("SELECT * FROM admin where user_id=@USERID and user_pwd=@PASSWORD");

cmd.Parameters.Add(new SqlParameter("@USERID", userIDTextbox.Value));
cmd.Parameters.Add(new SqlParameter("@PASSWORD", passwordTextbox.Value));


You will to replace userIDTextbox and passwordTextbox with the names you are using for the text boxes.
 
Share this answer
 
ofcource it causes sqlinjection attack
you can use like this

SqlCommand cmd = new SqlCommand("SELECT * FROM admin where user_id='"+usernametextbox.Text+"' and user_pwd='"+passwordtexboxid.Text+"'");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900