Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code, and I have some field in this combo box but I can get any information after search .

sql = "SELECT * FROM Reg_info where '" + comboBox2.Text+ "'='" + textBox4.Text + "'";

What I have tried:

sql = "SELECT * FROM Reg_info where '" + comboBox2.Text+ "'='" + textBox4.Text + "'";
Posted
Comments
Sergey Alexandrovich Kryukov 11-Feb-16 13:59pm    
And the question is?...
Your code is just SQL, it has nothing to do with combo box...
—SA

First off, don't do that. Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
You are probably OK with the Combobox - but check it, very, very carefully - if it's not a fixed list then you are going to have to sanitise it damn carefully. The text box is a definate no-no - any user with access to it and a keyboard can destroy your DB just by typing...

But as to why you get nothing useful - it's probably your use of quotes around the column name. That turns it into a string, and means that unless the text box contains exactly the same string the query will never return any records.
Remove the quotes, check and sanitize your combobox, and parameterise your textbox.
It should start to work then.
 
Share this answer
 
Comments
vipan.net 12-Feb-16 0:30am    
Great sir
plese remove single quotation from where combobox2.text.just use below
like as
sql = "SELECT * FROM Reg_info where " + comboBox2.Text+ " ='" + textBox4.Text + "'";
 
Share this answer
 
Comments
Adam_adam 11-Feb-16 14:15pm    
Thanks I did it..

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