Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i just need to write a select statement which satisfies 3 conditions.my table consist of 3 fields like userid,password and usertype.

i need to pass a select statement as command text in the front end which satisfies 3 conditions like

textbox1 value should be equal to userid field in the table.IIy
textbox2 value should be equal to password.
textbox3 value should be equal to usertype

i dont know how to pass multiple conditions in select statement like how to check userid=textbox1 value,password=textbox2 value and usertype =textbox3 value

can anyone plss help me..................
Posted
Updated 20-Mar-12 3:09am
v2
Comments
Rajesh Anuhya 20-Mar-12 9:09am    
Sounds like Homework..
--RA

You can use the AND keyword in any sql statement with WHERE like this

C#
query = "SELECT userid, password, usertype FROM users WHERE userid = @userid AND password = @password AND usertype = @usertype";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@userid", textbox1.Text);
cmd.Parameters.AddWithValue("@password", textbox2.Text);
cmd.Parameters.AddWithValue("@usertype", textbox3.Text);


take note how I used a parameterised query instead of directly concatenating the text boxes values.
 
Share this answer
 
Comments
Abhinav S 20-Mar-12 9:52am    
My 5.
Wayne Gaylard 20-Mar-12 10:06am    
Thanks Abhinav!
ProEnggSoft 20-Mar-12 11:56am    
Succinct and to the point. +5
Wayne Gaylard 21-Mar-12 2:07am    
Thanks!
matthewlink77 21-Mar-12 2:02am    
good answer!
Here[^] is a good example for you (select command with parameters) that should help you get started.
 
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