Click here to Skip to main content
16,017,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay so I can't seem to figure out what is wrong with the query I'm trying to do.

Here is the code I have

C#
string name;
name = cbxnames.SelectedValue.ToString();
myConnection.GetConnection();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM users WHERE name= '+name+'", myConnection.GetConnection());



What i need the query to lok like to actually return somthing from my db is
"SELECT * FROM users WHERE name = 'randomname'"


But I cannot figure out how to escape the strings to make it do that.
Posted
Updated 28-Oct-10 22:26pm
v2
Comments
Dalek Dave 29-Oct-10 4:26am    
Edited for Grammar and Readability.

1 solution

MySqlCommand cmd = new MySqlCommand("SELECT * FROM users WHERE name ='" +name+"'",myConnection.GetConnection());
 
Share this answer
 
Comments
Tunacha 29-Oct-10 3:17am    
umm that i=did it work, did i maybe not define the name variable correctly?

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